

``` r
#INTRO: LOADING PACKAGES ETC----
library(foreign)
library(reshape2)
library(data.table)
library(stargazer)
library(MatchIt)
#library(nonrandom)
library(ggplot2)
#library(gdata1)
library(gmodels)
library(gridExtra)
library(haven)
library(plyr)
#library(car)
#library(xlsx)
library(tidyr)
library(reshape)
library(countrycode)
#library(dGlyr)
library(readr)
library(gnm)
library(MNP)
```

```
## MNP: Fitting the Multinomial Probit Model
## Version: 3.1-5
## Authors: Kosuke Imai [aut, cre],
##   David van Dyk [aut],
##   Hubert Jin [ctb]
```

``` r
library(nls2)
library(nlstools)
library(stats)
library(dplyr)
library(matrixStats)
library(miceadds)
```

```
## Loading required package: mice
```

```
## 
## Attaching package: 'mice'
```

```
## The following object is masked from 'package:stats':
## 
##     filter
```

```
## The following objects are masked from 'package:base':
## 
##     cbind, rbind
```

```
## * miceadds 3.17-44 (2024-01-08 19:08:24)
```

```
## 
## Attaching package: 'miceadds'
```

```
## The following object is masked from 'package:common':
## 
##     source.all
```

``` r
library(minpack.lm)
library(lfe)
```

```
## Loading required package: Matrix
```

```
## 
## Attaching package: 'Matrix'
```

```
## The following object is masked from 'package:reshape':
## 
##     expand
```

```
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
```

```
## Registered S3 method overwritten by 'lfe':
##   method    from 
##   nobs.felm broom
```

```
## 
## Attaching package: 'lfe'
```

```
## The following object is masked from 'package:lmtest':
## 
##     waldtest
```

``` r
library(lubridate)
library(AER)
library(reshape)
library(reshape2)
library(tictoc)
library(xtable)
library(Formula)
library(mlogit)
```

```
## Loading required package: dfidx
```

```
## 
## Attaching package: 'dfidx'
```

```
## The following objects are masked from 'package:plyr':
## 
##     arrange, mutate
```

```
## The following object is masked from 'package:stats':
## 
##     filter
```

```
## 
## Attaching package: 'mlogit'
```

```
## The following object is masked from 'package:lfe':
## 
##     waldtest
```

``` r
library(plm)
```

```
## 
## Attaching package: 'plm'
```

```
## The following object is masked from 'package:mlogit':
## 
##     has.intercept
```

```
## The following object is masked from 'package:lfe':
## 
##     sargan
```

```
## The following objects are masked from 'package:dplyr':
## 
##     between, lag, lead
```

```
## The following object is masked from 'package:data.table':
## 
##     between
```

``` r
library(survival)
library(plotly)
```

```
## 
## Attaching package: 'plotly'
```

```
## The following object is masked from 'package:reshape':
## 
##     rename
```

```
## The following objects are masked from 'package:plyr':
## 
##     arrange, mutate, rename, summarise
```

```
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
```

```
## The following object is masked from 'package:stats':
## 
##     filter
```

```
## The following object is masked from 'package:graphics':
## 
##     layout
```

``` r
library(alpaca)
library(lmtest)
library(sandwich)
# library(mnlogit)

library(foreach)#parallel foreach
```

```
## 
## Attaching package: 'foreach'
```

```
## The following objects are masked from 'package:purrr':
## 
##     accumulate, when
```

``` r
library(iterators)
library(parallel)
library(doParallel)

library(msm)
library(tikzDevice)

library(openxlsx)#read.xlsx

library(labelled)#change labels to columns

options(width=1000)#set max characters shown
options(max.print=100000)#set max rows shown console

# !diagnostics suppress=Dsvr,Dgdm

rm(list=ls())
cat("\014")
```



``` r
#READ DATA:----

##read CSES data:
load("d29_CSES.RData")
dc=d
rm(d)


##read Leadership Project data (LP); Political Leaders and Democratic Elections:
dl=read_dta("LEADERS.dta")

#code variables:
colnames(dl)[colnames(dl)=="COUNTRY"]="Ec"
colnames(dl)[colnames(dl)=="ELECTION"]="Ey"
colnames(dl)[colnames(dl)=="PSTACK"]="PartyID"
colnames(dl)[colnames(dl)=="RID"]="Rid"
colnames(dl)[colnames(dl)=="WEIGHT1"]="Rwd"
dl$Rwd[dl$Rwd==0]=1#missing weight put to neutral weight of 1
colnames(dl)[colnames(dl)=="TURNOUT"]="Vt"
colnames(dl)[colnames(dl)=="RECALL"]="Vn"
colnames(dl)[colnames(dl)=="LR_SELF"]="LRR"
colnames(dl)[colnames(dl)=="SYMP"]="Pl"
colnames(dl)[colnames(dl)=="LERA"]="Ll"
colnames(dl)[colnames(dl)=="LR"]="LRP"
colnames(dl)[colnames(dl)=="SIZE"]="Ps"
dl$Rage=as.numeric(NA)#Respondent Age is not coded in LP dataset
colnames(dl)[colnames(dl)=="PIDIR"]="Pi"
dl$Pi[dl$Pi==0]=NA#set 0 to NA

#keep only variables of interest:
dl=dl[,c(1,2,6,9,10,17,21,14,23,3,31,5,33,12)]


#GERMANY EV de1:----
de1=read_dta("ZA3911_de_1961-1998.dta")
colnames(de1)
```

```
##   [1] "country"  "year"     "weight1"  "weight2"  "weight3"  "study"    "resp"     "ew_relat" "sex"      "born"     "age"      "urban"    "married"  "edu"      "whohead"  "work"     "hhwork"   "swork"    "rprof"    "sprof"    "hhprof"   "income"   "union"    "religion" "churchat" "region"   "polintr"  "s_polint" "mediause" "discuss"  "when"     "eff2"     "eff3"     "eff4"     "member"   "pid61"    "streng61" "pid65"    "streng65" "pid"      "strength" "symp1"    "symp2"    "symp3"    "symp4"    "symp5"    "sympl1"   "sympl2"   "sympl3"   "sympl4"   "sympl5"   "lrself"   "lrp1"     "lrp2"     "lrp3"     "lrp4"     "lrp5"     "economy1" "econom2a" "econom3a" "economy4" "govpol"   "sal1"     "sal2"     "sal3"     "sal4"     "sal5a"    "sal5b"    "sal6"     "sal7"     "sal8"     "sal9"     "sal10"    "sal11"    "sal11a"   "sal12"    "sal13"    "sal14"    "sal15"    "sal16"    "sal17"    "sal20"    "sal21"    "sal22"    "sal23"    "sal24"    "sal25"    "sal26"    "sal27"    "sal28"   
##  [91] "sal29"    "sal30"    "sal31"    "sal32"    "comp1"    "comp2"    "comp3"    "comp4"    "comp5a"   "comp5b"   "comp6"    "comp7"    "comp8"    "comp9"    "comp10"   "comp11"   "comp11a"  "comp12"   "comp13"   "comp14"   "comp15"   "comp16"   "comp17"   "comp20"   "comp21"   "comp22"   "comp23"   "comp24"   "comp25"   "comp26"   "comp27"   "comp28"   "comp29"   "comp30"   "comp31"   "comp32"   "turnout"  "pchoice"  "turnout2" "pchoice2" "s_lrp1"   "s_lrp2"   "s_lrp3"   "s_lrp4"   "s_lrp5"   "s_lrself"
```

``` r
colnames(de1)[colnames(de1)=="year"]="Ey"#Election Year
de1$Ey=as.numeric(de1$Ey)
de1=de1[!(de1$Ey %in% c(1969,1972)),]#get rid of elections without likability
colnames(de1)[colnames(de1)=="country"]="Ec"#Election Country
de1$Ec=as.numeric(de1$Ec)
colnames(de1)[colnames(de1)=="age"]="Rage"#Respondent Age
de1$Rage=as.numeric(de1$Rage)
de1$Rage[de1$Rage>100]=NA
#exclude East Germany in order to have West Germany as congruent electorate (and exclude Eastern Europe):
de1=de1[!(de1$Ey>1990&de1$region>10),]
#NB: in DEU_1990 even if the election included former East Germany, the survey did not
#Vt#Vote Turnout (0 did not vote; 1 voted)
colnames(de1)[colnames(de1)=="turnout"]="Vt"
de1$Vt[de1$Vt>2]=NA
de1$Vt[de1$Vt==2]=0
#"Va"#Vote Alphabetical (here numbers), by vote share:
de1$Va=NA
de1$Va[de1$Ey==1961&de1$pchoice==2]=1#1961:2,1,3
de1$Va[de1$Ey==1961&de1$pchoice==1]=2
de1$Va[de1$Ey==1961&de1$pchoice==3]=3
de1$Va[de1$Ey==1965&de1$pchoice==2]=1#1965:2,1,3
de1$Va[de1$Ey==1965&de1$pchoice==1]=2
de1$Va[de1$Ey==1965&de1$pchoice==3]=3
de1$Va[de1$Ey==1976&de1$pchoice==2]=1#1976:2,1,3
de1$Va[de1$Ey==1976&de1$pchoice==1]=2
de1$Va[de1$Ey==1976&de1$pchoice==3]=3
de1$Va[de1$Ey==1980&de1$pchoice==2]=1#1980:2,1,3
de1$Va[de1$Ey==1980&de1$pchoice==1]=2
de1$Va[de1$Ey==1980&de1$pchoice==3]=3
de1$Va[de1$Ey==1983&de1$pchoice==2]=1#1983:2,1,3
de1$Va[de1$Ey==1983&de1$pchoice==1]=2
de1$Va[de1$Ey==1983&de1$pchoice==3]=3
de1$Va[de1$Ey==1987&de1$pchoice==2]=1#1987:2,1,3
de1$Va[de1$Ey==1987&de1$pchoice==1]=2
de1$Va[de1$Ey==1987&de1$pchoice==3]=3
de1$Va[de1$Ey==1990&de1$pchoice==2]=1#1990:2,1,3,5
de1$Va[de1$Ey==1990&de1$pchoice==1]=2
de1$Va[de1$Ey==1990&de1$pchoice==3]=3
de1$Va[de1$Ey==1990&de1$pchoice==5]=4
de1$Va[de1$Ey==1994&de1$pchoice==2]=1#1994:2,1,4,3,5
de1$Va[de1$Ey==1994&de1$pchoice==1]=2
de1$Va[de1$Ey==1994&de1$pchoice==4]=3
de1$Va[de1$Ey==1994&de1$pchoice==3]=4
de1$Va[de1$Ey==1994&de1$pchoice==5]=5
de1$Va[de1$Ey==1998&de1$pchoice==1]=1#1998:1,2,4,3,5
de1$Va[de1$Ey==1998&de1$pchoice==2]=2
de1$Va[de1$Ey==1998&de1$pchoice==4]=3
de1$Va[de1$Ey==1998&de1$pchoice==3]=4
de1$Va[de1$Ey==1998&de1$pchoice==5]=5
colnames(de1)[colnames(de1)=="weight1"]="Rwd"#Respondent Weight Demographic
de1$Rwd=as.numeric(de1$Rwd)
#Number of Parties:
de1$NP=NA
de1$NP[de1$Ey==1961]=3
de1$NP[de1$Ey==1965]=3
de1$NP[de1$Ey==1969]=3
de1$NP[de1$Ey==1972]=3
de1$NP[de1$Ey==1976]=3
de1$NP[de1$Ey==1980]=3
de1$NP[de1$Ey==1983]=3
de1$NP[de1$Ey==1987]=3
de1$NP[de1$Ey==1990]=4
de1$NP[de1$Ey==1994]=5
de1$NP[de1$Ey==1998]=5
#party likability:
de1$Pl.1=NA
de1$Pl.2=NA
de1$Pl.3=NA
de1$Pl.4=NA
de1$Pl.5=NA
de1$Pl.6=NA
# de1$Pl.7=NA
de1$Pl.1[de1$Ey==1961]=de1$symp2[de1$Ey==1961]#1961:2,1,3
de1$Pl.2[de1$Ey==1961]=de1$symp1[de1$Ey==1961]
de1$Pl.3[de1$Ey==1961]=de1$symp3[de1$Ey==1961]
de1$Pl.1[de1$Ey==1965]=de1$symp2[de1$Ey==1965]#1965:2,1,3
de1$Pl.2[de1$Ey==1965]=de1$symp1[de1$Ey==1965]
de1$Pl.3[de1$Ey==1965]=de1$symp3[de1$Ey==1965]
de1$Pl.1[de1$Ey==1976]=de1$symp2[de1$Ey==1976]#1976:2,1,3
de1$Pl.2[de1$Ey==1976]=de1$symp1[de1$Ey==1976]
de1$Pl.3[de1$Ey==1976]=de1$symp3[de1$Ey==1976]
de1$Pl.1[de1$Ey==1980]=de1$symp2[de1$Ey==1980]#1980:2,1,3
de1$Pl.2[de1$Ey==1980]=de1$symp1[de1$Ey==1980]
de1$Pl.3[de1$Ey==1980]=de1$symp3[de1$Ey==1980]
de1$Pl.1[de1$Ey==1983]=de1$symp2[de1$Ey==1983]#1983:2,1,3
de1$Pl.2[de1$Ey==1983]=de1$symp1[de1$Ey==1983]
de1$Pl.3[de1$Ey==1983]=de1$symp3[de1$Ey==1983]
de1$Pl.1[de1$Ey==1987]=de1$symp2[de1$Ey==1987]#1987:2,1,3
de1$Pl.2[de1$Ey==1987]=de1$symp1[de1$Ey==1987]
de1$Pl.3[de1$Ey==1987]=de1$symp3[de1$Ey==1987]
de1$Pl.1[de1$Ey==1990]=de1$symp2[de1$Ey==1990]#1990:2,1,3,5
de1$Pl.2[de1$Ey==1990]=de1$symp1[de1$Ey==1990]
de1$Pl.3[de1$Ey==1990]=de1$symp3[de1$Ey==1990]
de1$Pl.4[de1$Ey==1990]=de1$symp5[de1$Ey==1990]
de1$Pl.1[de1$Ey==1994]=de1$symp2[de1$Ey==1994]#1994:2,1,4,3,5
de1$Pl.2[de1$Ey==1994]=de1$symp1[de1$Ey==1994]
de1$Pl.3[de1$Ey==1994]=de1$symp4[de1$Ey==1994]
de1$Pl.4[de1$Ey==1994]=de1$symp3[de1$Ey==1994]
de1$Pl.5[de1$Ey==1994]=de1$symp5[de1$Ey==1994]
de1$Pl.1[de1$Ey==1998]=de1$symp1[de1$Ey==1998]#1998:1,2,4,3,5
de1$Pl.2[de1$Ey==1998]=de1$symp2[de1$Ey==1998]
de1$Pl.3[de1$Ey==1998]=de1$symp4[de1$Ey==1998]
de1$Pl.4[de1$Ey==1998]=de1$symp3[de1$Ey==1998]
de1$Pl.5[de1$Ey==1998]=de1$symp5[de1$Ey==1998]
de1$Pl.1=de1$Pl.1-1#recoding to 0-10 scale
de1$Pl.2=de1$Pl.2-1
de1$Pl.3=de1$Pl.3-1
de1$Pl.4=de1$Pl.4-1
de1$Pl.5=de1$Pl.5-1
#leader likability:
de1$Ll.1=NA
de1$Ll.2=NA
de1$Ll.3=NA
de1$Ll.4=NA
de1$Ll.5=NA
de1$Ll.6=NA
# de1$Ll.7=NA
de1$Ll.1[de1$Ey==1961]=de1$sympl2[de1$Ey==1961]#1961:2,1,3
de1$Ll.2[de1$Ey==1961]=de1$sympl1[de1$Ey==1961]
de1$Ll.3[de1$Ey==1961]=de1$sympl3[de1$Ey==1961]
de1$Ll.1[de1$Ey==1965]=de1$sympl2[de1$Ey==1965]#1965:2,1,3
de1$Ll.2[de1$Ey==1965]=de1$sympl1[de1$Ey==1965]
de1$Ll.3[de1$Ey==1965]=de1$sympl3[de1$Ey==1965]
de1$Ll.1[de1$Ey==1976]=de1$sympl2[de1$Ey==1976]#1976:2,1,3
de1$Ll.2[de1$Ey==1976]=de1$sympl1[de1$Ey==1976]
de1$Ll.3[de1$Ey==1976]=de1$sympl3[de1$Ey==1976]
de1$Ll.1[de1$Ey==1980]=de1$sympl2[de1$Ey==1980]#1980:2,1,3
de1$Ll.2[de1$Ey==1980]=de1$sympl1[de1$Ey==1980]
de1$Ll.3[de1$Ey==1980]=de1$sympl3[de1$Ey==1980]
de1$Ll.1[de1$Ey==1983]=de1$sympl2[de1$Ey==1983]#1983:2,1,3
de1$Ll.2[de1$Ey==1983]=de1$sympl1[de1$Ey==1983]
de1$Ll.3[de1$Ey==1983]=de1$sympl3[de1$Ey==1983]
de1$Ll.1[de1$Ey==1987]=de1$sympl2[de1$Ey==1987]#1987:2,1,3
de1$Ll.2[de1$Ey==1987]=de1$sympl1[de1$Ey==1987]
de1$Ll.3[de1$Ey==1987]=de1$sympl3[de1$Ey==1987]
de1$Ll.1[de1$Ey==1990]=de1$sympl2[de1$Ey==1990]#1990:2,1,3,5
de1$Ll.2[de1$Ey==1990]=de1$sympl1[de1$Ey==1990]
de1$Ll.3[de1$Ey==1990]=de1$sympl3[de1$Ey==1990]
de1$Ll.4[de1$Ey==1990]=de1$sympl5[de1$Ey==1990]
de1$Ll.1[de1$Ey==1994]=de1$sympl2[de1$Ey==1994]#1994:2,1,4,3,5
de1$Ll.2[de1$Ey==1994]=de1$sympl1[de1$Ey==1994]
de1$Ll.3[de1$Ey==1994]=de1$sympl4[de1$Ey==1994]
de1$Ll.4[de1$Ey==1994]=de1$sympl3[de1$Ey==1994]
de1$Ll.5[de1$Ey==1994]=de1$sympl5[de1$Ey==1994]
de1$Ll.1[de1$Ey==1998]=de1$sympl1[de1$Ey==1998]#1998:1,2,4,3,5
de1$Ll.2[de1$Ey==1998]=de1$sympl2[de1$Ey==1998]
de1$Ll.3[de1$Ey==1998]=de1$sympl4[de1$Ey==1998]
de1$Ll.4[de1$Ey==1998]=de1$sympl3[de1$Ey==1998]
de1$Ll.5[de1$Ey==1998]=de1$sympl5[de1$Ey==1998]
de1$Ll.1=de1$Ll.1-1#recoding to 0-10 scale
de1$Ll.2=de1$Ll.2-1
de1$Ll.3=de1$Ll.3-1
de1$Ll.4=de1$Ll.4-1
de1$Ll.5=de1$Ll.5-1
#LRR=Left Right Respondent (voter LR self):
colnames(de1)[colnames(de1)=="lrself"]="LRR"
de1$LRR=de1$LRR-1#recoding to 0-10 scale
de1$LRR=as.numeric(de1$LRR)
#LRP.i=Left Right Parties:
de1$LRP.1=NA
de1$LRP.2=NA
de1$LRP.3=NA
de1$LRP.4=NA
de1$LRP.5=NA
de1$LRP.6=NA
# de1$LRP.7=NA
de1$LRP.1[de1$Ey==1961]=de1$lrp2[de1$Ey==1961]#1961:2,1,3
de1$LRP.2[de1$Ey==1961]=de1$lrp1[de1$Ey==1961]
de1$LRP.3[de1$Ey==1961]=de1$lrp3[de1$Ey==1961]
de1$LRP.1[de1$Ey==1965]=de1$lrp2[de1$Ey==1965]#1965:2,1,3
de1$LRP.2[de1$Ey==1965]=de1$lrp1[de1$Ey==1965]
de1$LRP.3[de1$Ey==1965]=de1$lrp3[de1$Ey==1965]
de1$LRP.1[de1$Ey==1976]=de1$lrp2[de1$Ey==1976]#1976:2,1,3
de1$LRP.2[de1$Ey==1976]=de1$lrp1[de1$Ey==1976]
de1$LRP.3[de1$Ey==1976]=de1$lrp3[de1$Ey==1976]
de1$LRP.1[de1$Ey==1980]=de1$lrp2[de1$Ey==1980]#1980:2,1,3
de1$LRP.2[de1$Ey==1980]=de1$lrp1[de1$Ey==1980]
de1$LRP.3[de1$Ey==1980]=de1$lrp3[de1$Ey==1980]
de1$LRP.1[de1$Ey==1983]=de1$lrp2[de1$Ey==1983]#1983:2,1,3
de1$LRP.2[de1$Ey==1983]=de1$lrp1[de1$Ey==1983]
de1$LRP.3[de1$Ey==1983]=de1$lrp3[de1$Ey==1983]
de1$LRP.1[de1$Ey==1987]=de1$lrp2[de1$Ey==1987]#1987:2,1,3
de1$LRP.2[de1$Ey==1987]=de1$lrp1[de1$Ey==1987]
de1$LRP.3[de1$Ey==1987]=de1$lrp3[de1$Ey==1987]
de1$LRP.1[de1$Ey==1990]=de1$lrp2[de1$Ey==1990]#1990:2,1,3,5
de1$LRP.2[de1$Ey==1990]=de1$lrp1[de1$Ey==1990]
de1$LRP.3[de1$Ey==1990]=de1$lrp3[de1$Ey==1990]
de1$LRP.4[de1$Ey==1990]=de1$lrp5[de1$Ey==1990]
de1$LRP.1[de1$Ey==1994]=de1$lrp2[de1$Ey==1994]#1994:2,1,4,3,5
de1$LRP.2[de1$Ey==1994]=de1$lrp1[de1$Ey==1994]
de1$LRP.3[de1$Ey==1994]=de1$lrp4[de1$Ey==1994]
de1$LRP.4[de1$Ey==1994]=de1$lrp3[de1$Ey==1994]
de1$LRP.5[de1$Ey==1994]=de1$lrp5[de1$Ey==1994]
de1$LRP.1[de1$Ey==1998]=de1$lrp1[de1$Ey==1998]#1998:1,2,4,3,5
de1$LRP.2[de1$Ey==1998]=de1$lrp2[de1$Ey==1998]
de1$LRP.3[de1$Ey==1998]=de1$lrp4[de1$Ey==1998]
de1$LRP.4[de1$Ey==1998]=de1$lrp3[de1$Ey==1998]
de1$LRP.5[de1$Ey==1998]=de1$lrp5[de1$Ey==1998]
de1$LRP.1=de1$LRP.1-1#recoding to 0-10 scale
de1$LRP.2=de1$LRP.2-1
de1$LRP.3=de1$LRP.3-1
de1$LRP.4=de1$LRP.4-1
de1$LRP.5=de1$LRP.5-1
#Elections with LRR and LRP:
de1$LR=NA
de1$LR[de1$Ey==1961]=0
de1$LR[de1$Ey==1965]=0
de1$LR[de1$Ey==1969]=1
de1$LR[de1$Ey==1972]=1
de1$LR[de1$Ey==1976]=1
de1$LR[de1$Ey==1980]=0
de1$LR[de1$Ey==1983]=1
de1$LR[de1$Ey==1987]=1
de1$LR[de1$Ey==1990]=1
de1$LR[de1$Ey==1994]=0
de1$LR[de1$Ey==1998]=1
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
# 1. MUCH BETTER                 
# 2. SOMEWHAT BETTER     
# 3. STAYED THE SAME              
# 4. SOMEWHAT WORSE
# 5. MUCH WORSE
colnames(de1)[colnames(de1)=="economy1"]="EeconS"
#recode EeconS from EV scale
# 1. GOTTEN BETTER c(1,2,3,4,5)
# 5. GOTTEN WORSE 
# to TEV scale, noting that the TEV used the conversion scale below for same elections:
# 0. Negative evaluation c(0, 0.25, 0.5, 0.75, 1)
# 1. Positive evaluation
de1$EeconS[de1$EeconS==1]=1
de1$EeconS[de1$EeconS==2]=0.75
de1$EeconS[de1$EeconS==3]=0.5
de1$EeconS[de1$EeconS==4]=0.25
de1$EeconS[de1$EeconS==5]=0
#Elections with EeconS:
de1$Eecon=NA
de1$Eecon[de1$Ey==1961]=1
de1$Eecon[de1$Ey==1965]=0
de1$Eecon[de1$Ey==1969]=1
de1$Eecon[de1$Ey==1972]=1
de1$Eecon[de1$Ey==1976]=1
de1$Eecon[de1$Ey==1980]=0
de1$Eecon[de1$Ey==1983]=1
de1$Eecon[de1$Ey==1987]=1
de1$Eecon[de1$Ey==1990]=1
de1$Eecon[de1$Ey==1994]=1
de1$Eecon[de1$Ey==1998]=0
#Seats to vote ratios:
de1$P1P2rat=NA
de1$P1P2rat[de1$Ey==1961]=0.99
de1$P1P2rat[de1$Ey==1965]=0.95
de1$P1P2rat[de1$Ey==1969]=0.98
de1$P1P2rat[de1$Ey==1972]=1.01
de1$P1P2rat[de1$Ey==1976]=0.99
de1$P1P2rat[de1$Ey==1980]=1.00
de1$P1P2rat[de1$Ey==1983]=0.99
de1$P1P2rat[de1$Ey==1987]=1.01
de1$P1P2rat[de1$Ey==1990]=1.02
de1$P1P2rat[de1$Ey==1994]=1.03
de1$P1P2rat[de1$Ey==1998]=1.04
#Gallagher Disproportionality measure:
de1$GDM=NA
de1$GDM[de1$Ey==1961]=3.43
de1$GDM[de1$Ey==1965]=2.31
de1$GDM[de1$Ey==1969]=3.92
de1$GDM[de1$Ey==1972]=0.67
de1$GDM[de1$Ey==1976]=0.59
de1$GDM[de1$Ey==1980]=1.41
de1$GDM[de1$Ey==1983]=0.50
de1$GDM[de1$Ey==1987]=0.76
de1$GDM[de1$Ey==1990]=4.63
de1$GDM[de1$Ey==1994]=2.22
de1$GDM[de1$Ey==1998]=3.15
#Party family:
de1$PartyFamilyCode1=30
de1$PartyFamilyCode2=50
de1$PartyFamilyCode3=40
de1$PartyFamilyCode4=10
de1$PartyFamilyCode5=20
de1$Pf.1=NA
de1$Pf.2=NA
de1$Pf.3=NA
de1$Pf.4=NA
de1$Pf.5=NA
de1$Pf.6=NA
# de1$Pf.7=NA
de1$Pf.1[de1$Ey==1961]=de1$PartyFamilyCode2[de1$Ey==1961]#1961:2,1,3
de1$Pf.2[de1$Ey==1961]=de1$PartyFamilyCode1[de1$Ey==1961]
de1$Pf.3[de1$Ey==1961]=de1$PartyFamilyCode3[de1$Ey==1961]
de1$Pf.1[de1$Ey==1965]=de1$PartyFamilyCode2[de1$Ey==1965]#1965:2,1,3
de1$Pf.2[de1$Ey==1965]=de1$PartyFamilyCode1[de1$Ey==1965]
de1$Pf.3[de1$Ey==1965]=de1$PartyFamilyCode3[de1$Ey==1965]
de1$Pf.1[de1$Ey==1976]=de1$PartyFamilyCode2[de1$Ey==1976]#1976:2,1,3
de1$Pf.2[de1$Ey==1976]=de1$PartyFamilyCode1[de1$Ey==1976]
de1$Pf.3[de1$Ey==1976]=de1$PartyFamilyCode3[de1$Ey==1976]
de1$Pf.1[de1$Ey==1980]=de1$PartyFamilyCode2[de1$Ey==1980]#1980:2,1,3
de1$Pf.2[de1$Ey==1980]=de1$PartyFamilyCode1[de1$Ey==1980]
de1$Pf.3[de1$Ey==1980]=de1$PartyFamilyCode3[de1$Ey==1980]
de1$Pf.1[de1$Ey==1983]=de1$PartyFamilyCode2[de1$Ey==1983]#1983:2,1,3
de1$Pf.2[de1$Ey==1983]=de1$PartyFamilyCode1[de1$Ey==1983]
de1$Pf.3[de1$Ey==1983]=de1$PartyFamilyCode3[de1$Ey==1983]
de1$Pf.1[de1$Ey==1987]=de1$PartyFamilyCode2[de1$Ey==1987]#1987:2,1,3
de1$Pf.2[de1$Ey==1987]=de1$PartyFamilyCode1[de1$Ey==1987]
de1$Pf.3[de1$Ey==1987]=de1$PartyFamilyCode3[de1$Ey==1987]
de1$Pf.1[de1$Ey==1990]=de1$PartyFamilyCode2[de1$Ey==1990]#1990:2,1,3,5
de1$Pf.2[de1$Ey==1990]=de1$PartyFamilyCode1[de1$Ey==1990]
de1$Pf.3[de1$Ey==1990]=de1$PartyFamilyCode3[de1$Ey==1990]
de1$Pf.4[de1$Ey==1990]=de1$PartyFamilyCode5[de1$Ey==1990]
de1$Pf.1[de1$Ey==1994]=de1$PartyFamilyCode2[de1$Ey==1994]#1994:2,1,4,3,5
de1$Pf.2[de1$Ey==1994]=de1$PartyFamilyCode1[de1$Ey==1994]
de1$Pf.3[de1$Ey==1994]=de1$PartyFamilyCode4[de1$Ey==1994]
de1$Pf.4[de1$Ey==1994]=de1$PartyFamilyCode3[de1$Ey==1994]
de1$Pf.5[de1$Ey==1994]=de1$PartyFamilyCode5[de1$Ey==1994]
de1$Pf.1[de1$Ey==1998]=de1$PartyFamilyCode1[de1$Ey==1998]#1998:1,2,4,3,5
de1$Pf.2[de1$Ey==1998]=de1$PartyFamilyCode2[de1$Ey==1998]
de1$Pf.3[de1$Ey==1998]=de1$PartyFamilyCode4[de1$Ey==1998]
de1$Pf.4[de1$Ey==1998]=de1$PartyFamilyCode3[de1$Ey==1998]
de1$Pf.5[de1$Ey==1998]=de1$PartyFamilyCode5[de1$Ey==1998]
#coding coalition status:
de1$CoalCode=1
#CMPid.i:
de1$CMPid.1=NA#create CMPid:
de1$CMPid.2=NA
de1$CMPid.3=NA
de1$CMPid.4=NA
de1$CMPid.5=NA
de1$CMPid.6=NA
de1$CMPid.1=as.numeric(de1$CMPid.1)#recode as numeric:
de1$CMPid.2=as.numeric(de1$CMPid.2)
de1$CMPid.3=as.numeric(de1$CMPid.3)
de1$CMPid.4=as.numeric(de1$CMPid.4)
de1$CMPid.5=as.numeric(de1$CMPid.5)
de1$CMPid.6=as.numeric(de1$CMPid.6)
#PrePost:
de1$PrePost=as.numeric(NA)
#"Pi"#Party identification:
#(there is not for 1961,1965)
de1$Pi=NA
de1$Pi[de1$Ey==1976&de1$pid==2]=1#1976:2,1,3
de1$Pi[de1$Ey==1976&de1$pid==1]=2
de1$Pi[de1$Ey==1976&de1$pid==3]=3
de1$Pi[de1$Ey==1980&de1$pid==2]=1#1980:2,1,3
de1$Pi[de1$Ey==1980&de1$pid==1]=2
de1$Pi[de1$Ey==1980&de1$pid==3]=3
de1$Pi[de1$Ey==1983&de1$pid==2]=1#1983:2,1,3
de1$Pi[de1$Ey==1983&de1$pid==1]=2
de1$Pi[de1$Ey==1983&de1$pid==3]=3
de1$Pi[de1$Ey==1987&de1$pid==2]=1#1987:2,1,3
de1$Pi[de1$Ey==1987&de1$pid==1]=2
de1$Pi[de1$Ey==1987&de1$pid==3]=3
de1$Pi[de1$Ey==1990&de1$pid==2]=1#1990:2,1,3,5
de1$Pi[de1$Ey==1990&de1$pid==1]=2
de1$Pi[de1$Ey==1990&de1$pid==3]=3
de1$Pi[de1$Ey==1990&de1$pid==5]=4
de1$Pi[de1$Ey==1994&de1$pid==2]=1#1994:2,1,4,3,5
de1$Pi[de1$Ey==1994&de1$pid==1]=2
de1$Pi[de1$Ey==1994&de1$pid==4]=3
de1$Pi[de1$Ey==1994&de1$pid==3]=4
de1$Pi[de1$Ey==1994&de1$pid==5]=5
de1$Pi[de1$Ey==1998&de1$pid==1]=1#1998:1,2,4,3,5
de1$Pi[de1$Ey==1998&de1$pid==2]=2
de1$Pi[de1$Ey==1998&de1$pid==4]=3
de1$Pi[de1$Ey==1998&de1$pid==3]=4
de1$Pi[de1$Ey==1998&de1$pid==5]=5
#subset:
colnames(de1)
```

```
##   [1] "Ec"               "Ey"               "Rwd"              "weight2"          "weight3"          "study"            "resp"             "ew_relat"         "sex"              "born"             "Rage"             "urban"            "married"          "edu"              "whohead"          "work"             "hhwork"           "swork"            "rprof"            "sprof"            "hhprof"           "income"           "union"            "religion"         "churchat"         "region"           "polintr"          "s_polint"         "mediause"         "discuss"          "when"             "eff2"             "eff3"             "eff4"             "member"           "pid61"            "streng61"         "pid65"            "streng65"         "pid"              "strength"         "symp1"            "symp2"            "symp3"            "symp4"            "symp5"            "sympl1"           "sympl2"           "sympl3"           "sympl4"           "sympl5"           "LRR"             
##  [53] "lrp1"             "lrp2"             "lrp3"             "lrp4"             "lrp5"             "EeconS"           "econom2a"         "econom3a"         "economy4"         "govpol"           "sal1"             "sal2"             "sal3"             "sal4"             "sal5a"            "sal5b"            "sal6"             "sal7"             "sal8"             "sal9"             "sal10"            "sal11"            "sal11a"           "sal12"            "sal13"            "sal14"            "sal15"            "sal16"            "sal17"            "sal20"            "sal21"            "sal22"            "sal23"            "sal24"            "sal25"            "sal26"            "sal27"            "sal28"            "sal29"            "sal30"            "sal31"            "sal32"            "comp1"            "comp2"            "comp3"            "comp4"            "comp5a"           "comp5b"           "comp6"            "comp7"            "comp8"            "comp9"           
## [105] "comp10"           "comp11"           "comp11a"          "comp12"           "comp13"           "comp14"           "comp15"           "comp16"           "comp17"           "comp20"           "comp21"           "comp22"           "comp23"           "comp24"           "comp25"           "comp26"           "comp27"           "comp28"           "comp29"           "comp30"           "comp31"           "comp32"           "Vt"               "pchoice"          "turnout2"         "pchoice2"         "s_lrp1"           "s_lrp2"           "s_lrp3"           "s_lrp4"           "s_lrp5"           "s_lrself"         "Va"               "NP"               "Pl.1"             "Pl.2"             "Pl.3"             "Pl.4"             "Pl.5"             "Pl.6"             "Ll.1"             "Ll.2"             "Ll.3"             "Ll.4"             "Ll.5"             "Ll.6"             "LRP.1"            "LRP.2"            "LRP.3"            "LRP.4"            "LRP.5"            "LRP.6"           
## [157] "LR"               "Eecon"            "P1P2rat"          "GDM"              "PartyFamilyCode1" "PartyFamilyCode2" "PartyFamilyCode3" "PartyFamilyCode4" "PartyFamilyCode5" "Pf.1"             "Pf.2"             "Pf.3"             "Pf.4"             "Pf.5"             "Pf.6"             "CoalCode"         "CMPid.1"          "CMPid.2"          "CMPid.3"          "CMPid.4"          "CMPid.5"          "CMPid.6"          "PrePost"          "Pi"
```

``` r
de1=de1[,c(1,2,3,138,127,137,139:150,157,52,151:156,158,58,159,160,166:179,11,180)]
colnames(de1)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
de1[colnames(de1)]=sapply(de1[colnames(de1)],as.numeric)


#DENMARK EV de2:----
de2=read_dta("ZA3911_dk_1971-1998.dta")
colnames(de2)
```

```
##   [1] "country"  "year"     "resp"     "weight"   "sex"      "born"     "age"      "ageca"    "married"  "urban"    "region"   "eduhh"    "eduown"   "churchat" "classdk"  "public"   "subcla"   "subclb"   "union"    "ownhouse" "housing"  "polintr"  "mediatv"  "mediatv2" "mediara"  "mediaavi" "discusfa" "discusfr" "discusco" "when"     "effici1"  "effici2"  "effici3"  "effici4"  "effici5"  "member"   "membpar"  "pidfeel"  "pida"     "pidb"     "strength" "symp1"    "symp2"    "symp3"    "symp4"    "symp5"    "symp6"    "symp11"   "symp15"   "symp16"   "symp17"   "symp18"   "symp19"   "symp22"   "symp25"   "symp26"   "symp28"   "symp31"   "sympl1"   "sympl2"   "sympl3"   "sympl4"   "sympl6"   "sympl15"  "sympl17"  "sympl22"  "sympl25"  "sympl26"  "sympl28"  "lrsp"     "lrp1"     "lrp2"     "lrp3"     "lrp4"     "lrp6"     "lrp15"    "lrp17"    "lrp22"    "lrp26"    "lrp28"    "economy1" "moral1"   "state1"   "state2"   "author1"  "author2"  "inglhart" "imp1"     "imp2"     "imp3"    
##  [91] "turnout"  "vote"     "rturnout" "rvote"    "isnato"   "issosec"  "iseec"    "isecde"   "istax"    "isnucl"   "isdemo"   "issocexp" "isnatind" "isincdif" "isdecmor" "owinc71"  "houinc71" "spinc71"  "owinc73"  "houinc73" "spinc73"  "age75"    "owinc75"  "houinc75" "age77"    "owinc77"  "houinc77" "owinc79"  "houinc79" "owinc81"  "houinc81" "owinc84"  "houinc84" "owinc87"  "houinc87" "owinc88"  "houinc88" "owinc90"  "houinc90" "owinc94"  "houinc94" "weigde98" "weigpo98" "owinc98"  "houinc98" "owhou98"  "streng98"
```

``` r
colnames(de2)[colnames(de2)=="year"]="Ey"#Election Year
de2=de2[de2$Ey %in% c(1971,1973,1994,1998),]#get rid of elections without likability
colnames(de2)[colnames(de2)=="country"]="Ec"#Election Country
de2$Ec=as.numeric(de2$Ec)
colnames(de2)[colnames(de2)=="age"]="Rage"#Respondent Age
de2$Rage=as.numeric(de2$Rage)
de2$Rage[de2$Rage>100]=NA
#Vt#Vote Turnout (0 did not vote; 1 voted)
colnames(de2)[colnames(de2)=="turnout"]="Vt"
de2$Vt[de2$Vt>2]=NA
de2$Vt[de2$Vt==2]=0
#"Va"#Vote Alphabetical (here numbers), by vote share:
de2$Va=NA
de2$Va[de2$Ey==1971&de2$vote==1]=1#1971:1,3,22,2,6,17
de2$Va[de2$Ey==1971&de2$vote==3]=2
de2$Va[de2$Ey==1971&de2$vote==22]=3
de2$Va[de2$Ey==1971&de2$vote==2]=4
de2$Va[de2$Ey==1971&de2$vote==6]=5
de2$Va[de2$Ey==1971&de2$vote==17]=6
de2$Va[de2$Ey==1973&de2$vote==1]=1#1973:1,26,22,2,3,4
de2$Va[de2$Ey==1973&de2$vote==26]=2
de2$Va[de2$Ey==1973&de2$vote==22]=3
de2$Va[de2$Ey==1973&de2$vote==2]=4
de2$Va[de2$Ey==1973&de2$vote==3]=5
de2$Va[de2$Ey==1973&de2$vote==4]=6
de2$Va[de2$Ey==1994&de2$vote==1]=1#1994:1,22,3,6,26,2
de2$Va[de2$Ey==1994&de2$vote==22]=2
de2$Va[de2$Ey==1994&de2$vote==3]=3
de2$Va[de2$Ey==1994&de2$vote==6]=4
de2$Va[de2$Ey==1994&de2$vote==26]=5
de2$Va[de2$Ey==1994&de2$vote==2]=6
de2$Va[de2$Ey==1998&de2$vote==1]=1#1998:1,22,3,6,(15),4,2
de2$Va[de2$Ey==1998&de2$vote==22]=2
de2$Va[de2$Ey==1998&de2$vote==3]=3
de2$Va[de2$Ey==1998&de2$vote==6]=4
de2$Va[de2$Ey==1998&de2$vote==4]=5
de2$Va[de2$Ey==1998&de2$vote==2]=6
colnames(de2)[colnames(de2)=="weight"]="Rwd"#Respondent Weight Demographic (there's no weight, all entries are 1)
de2$Rwd=1#no info on weights
#Number of Parties:
de2$NP=NA
de2$NP[de2$Ey==1971]=6
de2$NP[de2$Ey==1973]=6
de2$NP[de2$Ey==1994]=6
de2$NP[de2$Ey==1998]=6
#party likability:
de2$Pl.1=NA
de2$Pl.2=NA
de2$Pl.3=NA
de2$Pl.4=NA
de2$Pl.5=NA
de2$Pl.6=NA
# de2$Pl.7=NA
de2$Pl.1[de2$Ey==1971]=de2$symp1[de2$Ey==1971]#1971:1,3,22,2,6,17
de2$Pl.2[de2$Ey==1971]=de2$symp3[de2$Ey==1971]
de2$Pl.3[de2$Ey==1971]=de2$symp22[de2$Ey==1971]
de2$Pl.4[de2$Ey==1971]=de2$symp2[de2$Ey==1971]
de2$Pl.5[de2$Ey==1971]=de2$symp6[de2$Ey==1971]
de2$Pl.6[de2$Ey==1971]=de2$symp17[de2$Ey==1971]
de2$Pl.1[de2$Ey==1973]=de2$symp1[de2$Ey==1973]#1973:1,26,22,2,3,4
de2$Pl.2[de2$Ey==1973]=de2$symp26[de2$Ey==1973]
de2$Pl.3[de2$Ey==1973]=de2$symp22[de2$Ey==1973]
de2$Pl.4[de2$Ey==1973]=de2$symp2[de2$Ey==1973]
de2$Pl.5[de2$Ey==1973]=de2$symp3[de2$Ey==1973]
de2$Pl.6[de2$Ey==1973]=de2$symp4[de2$Ey==1973]
de2$Pl.1[de2$Ey==1994]=de2$symp1[de2$Ey==1994]#1994:1,22,3,6,26,2
de2$Pl.2[de2$Ey==1994]=de2$symp22[de2$Ey==1994]
de2$Pl.3[de2$Ey==1994]=de2$symp3[de2$Ey==1994]
de2$Pl.4[de2$Ey==1994]=de2$symp6[de2$Ey==1994]
de2$Pl.5[de2$Ey==1994]=de2$symp26[de2$Ey==1994]
de2$Pl.6[de2$Ey==1994]=de2$symp2[de2$Ey==1994]
de2$Pl.1[de2$Ey==1998]=de2$symp1[de2$Ey==1998]#1998:1,22,3,6,(15),4,2
de2$Pl.2[de2$Ey==1998]=de2$symp22[de2$Ey==1998]
de2$Pl.3[de2$Ey==1998]=de2$symp3[de2$Ey==1998]
de2$Pl.4[de2$Ey==1998]=de2$symp6[de2$Ey==1998]
de2$Pl.5[de2$Ey==1998]=de2$symp4[de2$Ey==1998]
de2$Pl.6[de2$Ey==1998]=de2$symp2[de2$Ey==1998]
de2$Pl.1[de2$Pl.1>10]=NA#recoding to 0-10 scale
de2$Pl.2[de2$Pl.2>10]=NA
de2$Pl.3[de2$Pl.3>10]=NA
de2$Pl.4[de2$Pl.4>10]=NA
de2$Pl.5[de2$Pl.5>10]=NA
de2$Pl.6[de2$Pl.6>10]=NA
#leader likability:
de2$Ll.1=NA
de2$Ll.2=NA
de2$Ll.3=NA
de2$Ll.4=NA
de2$Ll.5=NA
de2$Ll.6=NA
# de2$Ll.7=NA
de2$Ll.1[de2$Ey==1971]=de2$sympl1[de2$Ey==1971]#1971:1,3,22,2,6,17
de2$Ll.2[de2$Ey==1971]=de2$sympl3[de2$Ey==1971]
de2$Ll.3[de2$Ey==1971]=de2$sympl22[de2$Ey==1971]
de2$Ll.4[de2$Ey==1971]=de2$sympl2[de2$Ey==1971]
de2$Ll.5[de2$Ey==1971]=de2$sympl6[de2$Ey==1971]
de2$Ll.6[de2$Ey==1971]=de2$sympl17[de2$Ey==1971]
de2$Ll.1[de2$Ey==1973]=de2$sympl1[de2$Ey==1973]#1973:1,26,22,2,3,4
de2$Ll.2[de2$Ey==1973]=de2$sympl26[de2$Ey==1973]
de2$Ll.3[de2$Ey==1973]=de2$sympl22[de2$Ey==1973]
de2$Ll.4[de2$Ey==1973]=de2$sympl2[de2$Ey==1973]
de2$Ll.5[de2$Ey==1973]=de2$sympl3[de2$Ey==1973]
de2$Ll.6[de2$Ey==1973]=de2$sympl4[de2$Ey==1973]
de2$Ll.1[de2$Ey==1994]=de2$sympl1[de2$Ey==1994]#1994:1,22,3,6,26,2
de2$Ll.2[de2$Ey==1994]=de2$sympl22[de2$Ey==1994]
de2$Ll.3[de2$Ey==1994]=de2$sympl3[de2$Ey==1994]
de2$Ll.4[de2$Ey==1994]=de2$sympl6[de2$Ey==1994]
de2$Ll.5[de2$Ey==1994]=de2$sympl26[de2$Ey==1994]
de2$Ll.6[de2$Ey==1994]=de2$sympl2[de2$Ey==1994]
de2$Ll.1[de2$Ey==1998]=de2$sympl1[de2$Ey==1998]#1998:1,22,3,6,(15),4,2
de2$Ll.2[de2$Ey==1998]=de2$sympl22[de2$Ey==1998]
de2$Ll.3[de2$Ey==1998]=de2$sympl3[de2$Ey==1998]
de2$Ll.4[de2$Ey==1998]=de2$sympl6[de2$Ey==1998]
de2$Ll.5[de2$Ey==1998]=de2$sympl4[de2$Ey==1998]
de2$Ll.6[de2$Ey==1998]=de2$sympl2[de2$Ey==1998]
de2$Ll.1[de2$Ll.1>10]=NA#recoding to 0-10 scale
de2$Ll.2[de2$Ll.2>10]=NA
de2$Ll.3[de2$Ll.3>10]=NA
de2$Ll.4[de2$Ll.4>10]=NA
de2$Ll.5[de2$Ll.5>10]=NA
de2$Ll.6[de2$Ll.6>10]=NA
#LRR=Left Right Respondent (voter LR self):
colnames(de2)[colnames(de2)=="lrsp"]="LRR"
de2$LRR=(de2$LRR-1)*10/9#recoding to 0-10 scale
de2$LRR[de2$LRR>10]=NA
de2$LRR=as.numeric(de2$LRR)
#LRP.i=Left Right Parties:
de2$LRP.1=NA
de2$LRP.2=NA
de2$LRP.3=NA
de2$LRP.4=NA
de2$LRP.5=NA
de2$LRP.6=NA
# de2$LRP.7=NA
de2$LRP.1[de2$Ey==1971]=de2$lrp1[de2$Ey==1971]#1971:1,3,22,2,6,17
de2$LRP.2[de2$Ey==1971]=de2$lrp3[de2$Ey==1971]
de2$LRP.3[de2$Ey==1971]=de2$lrp22[de2$Ey==1971]
de2$LRP.4[de2$Ey==1971]=de2$lrp2[de2$Ey==1971]
de2$LRP.5[de2$Ey==1971]=de2$lrp6[de2$Ey==1971]
de2$LRP.6[de2$Ey==1971]=de2$lrp17[de2$Ey==1971]
de2$LRP.1[de2$Ey==1973]=de2$lrp1[de2$Ey==1973]#1973:1,26,22,2,3,4
de2$LRP.2[de2$Ey==1973]=de2$lrp26[de2$Ey==1973]
de2$LRP.3[de2$Ey==1973]=de2$lrp22[de2$Ey==1973]
de2$LRP.4[de2$Ey==1973]=de2$lrp2[de2$Ey==1973]
de2$LRP.5[de2$Ey==1973]=de2$lrp3[de2$Ey==1973]
de2$LRP.6[de2$Ey==1973]=de2$lrp4[de2$Ey==1973]
de2$LRP.1[de2$Ey==1994]=de2$lrp1[de2$Ey==1994]#1994:1,22,3,6,26,2
de2$LRP.2[de2$Ey==1994]=de2$lrp22[de2$Ey==1994]
de2$LRP.3[de2$Ey==1994]=de2$lrp3[de2$Ey==1994]
de2$LRP.4[de2$Ey==1994]=de2$lrp6[de2$Ey==1994]
de2$LRP.5[de2$Ey==1994]=de2$lrp26[de2$Ey==1994]
de2$LRP.6[de2$Ey==1994]=de2$lrp2[de2$Ey==1994]
de2$LRP.1[de2$Ey==1998]=de2$lrp1[de2$Ey==1998]#1998:1,22,3,6,(15),4,2
de2$LRP.2[de2$Ey==1998]=de2$lrp22[de2$Ey==1998]
de2$LRP.3[de2$Ey==1998]=de2$lrp3[de2$Ey==1998]
de2$LRP.4[de2$Ey==1998]=de2$lrp6[de2$Ey==1998]
de2$LRP.5[de2$Ey==1998]=de2$lrp4[de2$Ey==1998]
de2$LRP.6[de2$Ey==1998]=de2$lrp2[de2$Ey==1998]
de2$LRP.1=(de2$LRP.1-1)*10/9#recoding to 0-10 scale
de2$LRP.1[de2$LRP.1>10]=NA
de2$LRP.2=(de2$LRP.2-1)*10/9
de2$LRP.2[de2$LRP.2>10]=NA
de2$LRP.3=(de2$LRP.3-1)*10/9
de2$LRP.3[de2$LRP.3>10]=NA
de2$LRP.4=(de2$LRP.4-1)*10/9
de2$LRP.4[de2$LRP.4>10]=NA
de2$LRP.5=(de2$LRP.5-1)*10/9
de2$LRP.5[de2$LRP.5>10]=NA
de2$LRP.6=(de2$LRP.6-1)*10/9
de2$LRP.6[de2$LRP.6>10]=NA
#Elections with LRR and LRP:
de2$LR=NA
de2$LR[de2$Ey==1971]=0
de2$LR[de2$Ey==1973]=0
de2$LR[de2$Ey==1994]=1
de2$LR[de2$Ey==1998]=1
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
de2$EeconS=NA#no data on economy state subjective
#Elections with EeconS:
de2$Eecon=0#(no data)
#Seats to vote ratios:
de2$P1P2rat=NA
de2$P1P2rat[de2$Ey==1971]=1.01
de2$P1P2rat[de2$Ey==1973]=1.02
de2$P1P2rat[de2$Ey==1994]=0.99
de2$P1P2rat[de2$Ey==1998]=1.00
#Gallagher Disproportionality measure:
de2$GDM=NA
de2$GDM[de2$Ey==1971]=3.45
de2$GDM[de2$Ey==1973]=1.20
de2$GDM[de2$Ey==1994]=1.57
de2$GDM[de2$Ey==1998]=0.42
#Party family:
de2$PartyFamilyCode1=30
de2$PartyFamilyCode2=40
de2$PartyFamilyCode3=60
de2$PartyFamilyCode4=60
de2$PartyFamilyCode6=20
de2$PartyFamilyCode17=50
de2$PartyFamilyCode22=40
de2$PartyFamilyCode26=70
de2$Pf.1=NA
de2$Pf.2=NA
de2$Pf.3=NA
de2$Pf.4=NA
de2$Pf.5=NA
de2$Pf.6=NA
# de2$Pf.7=NA
de2$Pf.1[de2$Ey==1971]=de2$PartyFamilyCode1[de2$Ey==1971]#1971:1,3,22,2,6,17
de2$Pf.2[de2$Ey==1971]=de2$PartyFamilyCode3[de2$Ey==1971]
de2$Pf.3[de2$Ey==1971]=de2$PartyFamilyCode22[de2$Ey==1971]
de2$Pf.4[de2$Ey==1971]=de2$PartyFamilyCode2[de2$Ey==1971]
de2$Pf.5[de2$Ey==1971]=de2$PartyFamilyCode6[de2$Ey==1971]
de2$Pf.6[de2$Ey==1971]=de2$PartyFamilyCode17[de2$Ey==1971]
de2$Pf.1[de2$Ey==1973]=de2$PartyFamilyCode1[de2$Ey==1973]#1973:1,26,22,2,3,4
de2$Pf.2[de2$Ey==1973]=de2$PartyFamilyCode26[de2$Ey==1973]
de2$Pf.3[de2$Ey==1973]=de2$PartyFamilyCode22[de2$Ey==1973]
de2$Pf.4[de2$Ey==1973]=de2$PartyFamilyCode2[de2$Ey==1973]
de2$Pf.5[de2$Ey==1973]=de2$PartyFamilyCode3[de2$Ey==1973]
de2$Pf.6[de2$Ey==1973]=de2$PartyFamilyCode4[de2$Ey==1973]
de2$Pf.1[de2$Ey==1994]=de2$PartyFamilyCode1[de2$Ey==1994]#1994:1,22,3,6,26,2
de2$Pf.2[de2$Ey==1994]=de2$PartyFamilyCode22[de2$Ey==1994]
de2$Pf.3[de2$Ey==1994]=de2$PartyFamilyCode3[de2$Ey==1994]
de2$Pf.4[de2$Ey==1994]=de2$PartyFamilyCode6[de2$Ey==1994]
de2$Pf.5[de2$Ey==1994]=de2$PartyFamilyCode26[de2$Ey==1994]
de2$Pf.6[de2$Ey==1994]=de2$PartyFamilyCode2[de2$Ey==1994]
de2$Pf.1[de2$Ey==1998]=de2$PartyFamilyCode1[de2$Ey==1998]#1998:1,22,3,6,(15),4,2
de2$Pf.2[de2$Ey==1998]=de2$PartyFamilyCode22[de2$Ey==1998]
de2$Pf.3[de2$Ey==1998]=de2$PartyFamilyCode3[de2$Ey==1998]
de2$Pf.4[de2$Ey==1998]=de2$PartyFamilyCode6[de2$Ey==1998]
de2$Pf.5[de2$Ey==1998]=de2$PartyFamilyCode4[de2$Ey==1998]
de2$Pf.6[de2$Ey==1998]=de2$PartyFamilyCode2[de2$Ey==1998]
#coding coalition status:
de2$CoalCode=0
#CMPid.i:
de2$CMPid.1=NA#create CMPid:
de2$CMPid.2=NA
de2$CMPid.3=NA
de2$CMPid.4=NA
de2$CMPid.5=NA
de2$CMPid.6=NA
de2$CMPid.1[de2$Ey==1971]=13320#assign CMPid by party size order for parties with likability:
de2$CMPid.2[de2$Ey==1971]=13620
de2$CMPid.3[de2$Ey==1971]=13420
de2$CMPid.4[de2$Ey==1971]=13410
de2$CMPid.5[de2$Ey==1971]=13230
de2$CMPid.6[de2$Ey==1971]=13520
de2$CMPid.1[de2$Ey==1973]=13320
de2$CMPid.2[de2$Ey==1973]=13951
de2$CMPid.3[de2$Ey==1973]=13420
de2$CMPid.4[de2$Ey==1973]=13410
de2$CMPid.5[de2$Ey==1973]=13620
de2$CMPid.6[de2$Ey==1973]=13330
de2$CMPid.1[de2$Ey==1994]=13320
de2$CMPid.2[de2$Ey==1994]=13420
de2$CMPid.3[de2$Ey==1994]=13620
de2$CMPid.4[de2$Ey==1994]=13230
de2$CMPid.5[de2$Ey==1994]=13951
de2$CMPid.6[de2$Ey==1994]=13410
de2$CMPid.1=as.numeric(de2$CMPid.1)#recode as numeric:
de2$CMPid.2=as.numeric(de2$CMPid.2)
de2$CMPid.3=as.numeric(de2$CMPid.3)
de2$CMPid.4=as.numeric(de2$CMPid.4)
de2$CMPid.5=as.numeric(de2$CMPid.5)
de2$CMPid.6=as.numeric(de2$CMPid.6)
#PrePost:
de2$PrePost=as.numeric(NA)
#"Pi"#Party identification:
#(there is not for 1971)
de2$Pi=NA
de2$Pi[de2$Ey==1973&de2$pida==1]=1#1973:1,26,22,2,3,4
de2$Pi[de2$Ey==1973&de2$pida==26]=2
de2$Pi[de2$Ey==1973&de2$pida==22]=3
de2$Pi[de2$Ey==1973&de2$pida==2]=4
de2$Pi[de2$Ey==1973&de2$pida==3]=5
de2$Pi[de2$Ey==1973&de2$pida==4]=6
de2$Pi[de2$Ey==1994&de2$pida==1]=1#1994:1,22,3,6,26,2
de2$Pi[de2$Ey==1994&de2$pida==22]=2
de2$Pi[de2$Ey==1994&de2$pida==3]=3
de2$Pi[de2$Ey==1994&de2$pida==6]=4
de2$Pi[de2$Ey==1994&de2$pida==26]=5
de2$Pi[de2$Ey==1994&de2$pida==2]=6
de2$Pi[de2$Ey==1998&de2$pida==1]=1#1998:1,22,3,6,(15),4,2
de2$Pi[de2$Ey==1998&de2$pida==22]=2
de2$Pi[de2$Ey==1998&de2$pida==3]=3
de2$Pi[de2$Ey==1998&de2$pida==6]=4
de2$Pi[de2$Ey==1998&de2$pida==4]=5
de2$Pi[de2$Ey==1998&de2$pida==2]=6
#subset:
colnames(de2)
```

```
##   [1] "Ec"                "Ey"                "resp"              "Rwd"               "sex"               "born"              "Rage"              "ageca"             "married"           "urban"             "region"            "eduhh"             "eduown"            "churchat"          "classdk"           "public"            "subcla"            "subclb"            "union"             "ownhouse"          "housing"           "polintr"           "mediatv"           "mediatv2"          "mediara"           "mediaavi"          "discusfa"          "discusfr"          "discusco"          "when"              "effici1"           "effici2"           "effici3"           "effici4"           "effici5"           "member"            "membpar"           "pidfeel"           "pida"              "pidb"              "strength"          "symp1"             "symp2"             "symp3"             "symp4"             "symp5"             "symp6"             "symp11"            "symp15"           
##  [50] "symp16"            "symp17"            "symp18"            "symp19"            "symp22"            "symp25"            "symp26"            "symp28"            "symp31"            "sympl1"            "sympl2"            "sympl3"            "sympl4"            "sympl6"            "sympl15"           "sympl17"           "sympl22"           "sympl25"           "sympl26"           "sympl28"           "LRR"               "lrp1"              "lrp2"              "lrp3"              "lrp4"              "lrp6"              "lrp15"             "lrp17"             "lrp22"             "lrp26"             "lrp28"             "economy1"          "moral1"            "state1"            "state2"            "author1"           "author2"           "inglhart"          "imp1"              "imp2"              "imp3"              "Vt"                "vote"              "rturnout"          "rvote"             "isnato"            "issosec"           "iseec"             "isecde"           
##  [99] "istax"             "isnucl"            "isdemo"            "issocexp"          "isnatind"          "isincdif"          "isdecmor"          "owinc71"           "houinc71"          "spinc71"           "owinc73"           "houinc73"          "spinc73"           "age75"             "owinc75"           "houinc75"          "age77"             "owinc77"           "houinc77"          "owinc79"           "houinc79"          "owinc81"           "houinc81"          "owinc84"           "houinc84"          "owinc87"           "houinc87"          "owinc88"           "houinc88"          "owinc90"           "houinc90"          "owinc94"           "houinc94"          "weigde98"          "weigpo98"          "owinc98"           "houinc98"          "owhou98"           "streng98"          "Va"                "NP"                "Pl.1"              "Pl.2"              "Pl.3"              "Pl.4"              "Pl.5"              "Pl.6"              "Ll.1"              "Ll.2"             
## [148] "Ll.3"              "Ll.4"              "Ll.5"              "Ll.6"              "LRP.1"             "LRP.2"             "LRP.3"             "LRP.4"             "LRP.5"             "LRP.6"             "LR"                "EeconS"            "Eecon"             "P1P2rat"           "GDM"               "PartyFamilyCode1"  "PartyFamilyCode2"  "PartyFamilyCode3"  "PartyFamilyCode4"  "PartyFamilyCode6"  "PartyFamilyCode17" "PartyFamilyCode22" "PartyFamilyCode26" "Pf.1"              "Pf.2"              "Pf.3"              "Pf.4"              "Pf.5"              "Pf.6"              "CoalCode"          "CMPid.1"           "CMPid.2"           "CMPid.3"           "CMPid.4"           "CMPid.5"           "CMPid.6"           "PrePost"           "Pi"
```

``` r
de2=de2[,c(1,2,4,139,91,138,140:151,158,70,152:157,160,159,161,162,171:184,7,185)]
colnames(de2)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
de2[colnames(de2)]=sapply(de2[colnames(de2)],as.numeric)
    
    
#GREAT BRITAIN EV de3:----
#first merge datasets:
#de31=read_dta("ZA3911_gb_1964.dta")#no likability
#de32=read_dta("ZA3911_gb_1966.dta")#no likability
#de33=read_dta("ZA3911_gb_1970.dta")#no likability
de34=read_dta("ZA3911_gb_1974f.dta")
de35=read_dta("ZA3911_gb_1974o.dta")
de35$year=1975#temporarily modifying 1974o year to code all the variables with
#unique election-year, it will be modified before the analysis
de36=read_dta("ZA3911_gb_1979.dta")
#de37=read_dta("ZA3911_gb_1983.dta")#different likability scale (and vote for other patries not coded)
#de38=read_dta("ZA3911_gb_1987.dta")#different likability scale (and leader Vs party)
#de39=read_dta("ZA3911_gb_1992.dta")#different likability scale (and leader Vs party)
de310=read_dta("ZA3911_gb_1997.dta")
de311=read_dta("ZA3911_gb_2001.dta")
de3=rbind(de34,de35,de36,de310,de311)
rm(de34,de35,de36,de310,de311)
colnames(de3)
```

```
##   [1] "country"  "year"     "weight"   "study"    "resp"     "sex"      "born"     "age"      "married"  "region"   "edu"      "religion" "churchat" "egpclass" "subclass" "hincome"  "union"    "housing"  "campintr" "carewon"  "tvradio"  "newspapr" "camptalk" "when"     "elecresp" "ptsresp"  "member"   "pid"      "strength" "symp1"    "symp2"    "sympl1"   "sympl2"   "lrsp"     "lrp1"     "lrp2"     "lrp3"     "incprcsa" "incprcsb" "penssrvs" "strksprb" "tupower"  "busnpowr" "natlview" "deathpen" "immgrvw"  "nclrwepn" "eecview"  "turnout"  "vote"     "rturnout" "vote1ago" "typeschl" "rsincome" "intrspol" "tvpoltcs" "newsppol" "poltalka" "symp3"    "sympl3"   "britecon" "toopwrtu" "toopwrbb" "srvsview" "pricsimp" "natlimp"  "strksimp" "wagesimp" "srvsimp"  "pensnimp" "eecimp"   "taxesimp" "commimp"  "public"   "abortion" "sexmedia" "compschl" "wrkrssay" "nhsspend" "wlfrben"  "redistrb" "oppblack" "eqoppwom" "unempimp" "housgimp" "nsoilimp" "brdcasts" "tulaws"   "stifsent" "nucpind" 
##  [91] "scotass"  "taxsvimp" "tulawimp" "lawimp"   "racrlimp" "symp4"    "sympl4"   "priveduc" "privmed"  "makejobs" "rtxspd"   "unemcrim" "immgrcut" "nucps2fr" "inglhart" "britnclr" "defspend" "inflimp"  "falksimp" "defimp"   "govnosay" "govcomp"  "votintr"  "fairshar" "richlaw"  "indust4"  "tradvals" "hlthimp"  "educimp"  "newsattn" "talkpol1" "tuntneed" "privent"  "publcown" "censor"   "pubmeet"  "gaysex"   "tolerant" "banparty" "eec"      "votjbprc" "votinceq" "votprnat" "votecind" "vottxspd" "tvnatfrq" "scotparl" "symp5"    "sympl5"   "lrp4"     "lrp5"     "kppound"  "impissue"
```

``` r
colnames(de3)[colnames(de3)=="year"]="Ey"#Election Year
de3$Ey=as.numeric(de3$Ey)
colnames(de3)[colnames(de3)=="country"]="Ec"#Election Country
de3$Ec=as.numeric(de3$Ec)
colnames(de3)[colnames(de3)=="age"]="Rage"#Respondent Age
de3$Rage=as.numeric(de3$Rage)
de3$Rage[de3$Rage>100]=NA
#Vt#Vote Turnout (0 did not vote; 1 voted)
colnames(de3)[colnames(de3)=="turnout"]="Vt"
de3$Vt[de3$Vt>2]=NA
#"Va"#Vote Alphabetical (here numbers), by vote share:
de3$Va=NA
de3$Va[de3$Ey==1974&de3$vote==2]=1#1974:2,1,3
de3$Va[de3$Ey==1974&de3$vote==1]=2
de3$Va[de3$Ey==1974&de3$vote==3]=3
de3$Va[de3$Ey==1975&de3$vote==2]=1#1975:2,1,3
de3$Va[de3$Ey==1975&de3$vote==1]=2
de3$Va[de3$Ey==1975&de3$vote==3]=3
de3$Va[de3$Ey==1979&de3$vote==1]=1#1979:1,2,3
de3$Va[de3$Ey==1979&de3$vote==2]=2
de3$Va[de3$Ey==1979&de3$vote==3]=3
de3$Va[de3$Ey==1997&de3$vote==2]=1#1997:2,1,3
de3$Va[de3$Ey==1997&de3$vote==1]=2
de3$Va[de3$Ey==1997&de3$vote==3]=3
de3$Va[de3$Ey==2001&de3$vote==2]=1#2001:2,1,3
de3$Va[de3$Ey==2001&de3$vote==1]=2
de3$Va[de3$Ey==2001&de3$vote==3]=3
colnames(de3)[colnames(de3)=="weight"]="Rwd"#Respondent Weight Demographic
de3$Rwd=as.numeric(de3$Rwd)
de3$Rwd[de3$Rwd==0]=1#missing weight put to neutral weight of 1
#Number of Parties:
de3$NP=NA
de3$NP[de3$Ey==1974]=3
de3$NP[de3$Ey==1975]=3
de3$NP[de3$Ey==1979]=3
de3$NP[de3$Ey==1997]=3
de3$NP[de3$Ey==2001]=3
#party likability:
de3$Pl.1=NA
de3$Pl.2=NA
de3$Pl.3=NA
de3$Pl.4=NA
de3$Pl.5=NA
de3$Pl.6=NA
de3$Pl.1[de3$Ey==1974]=de3$symp2[de3$Ey==1974]#1974:2,1,3
de3$Pl.2[de3$Ey==1974]=de3$symp1[de3$Ey==1974]
de3$Pl.3[de3$Ey==1974]=de3$symp3[de3$Ey==1974]
de3$Pl.1[de3$Ey==1975]=de3$symp2[de3$Ey==1975]#1975:2,1,3
de3$Pl.2[de3$Ey==1975]=de3$symp1[de3$Ey==1975]
de3$Pl.3[de3$Ey==1975]=de3$symp3[de3$Ey==1975]
de3$Pl.1[de3$Ey==1979]=de3$symp1[de3$Ey==1979]#1979:1,2,3
de3$Pl.2[de3$Ey==1979]=de3$symp2[de3$Ey==1979]
de3$Pl.3[de3$Ey==1979]=de3$symp3[de3$Ey==1979]
de3$Pl.1[de3$Ey==1997]=de3$symp2[de3$Ey==1997]#1997:2,1,3
de3$Pl.2[de3$Ey==1997]=de3$symp1[de3$Ey==1997]
de3$Pl.3[de3$Ey==1997]=de3$symp3[de3$Ey==1997]
de3$Pl.1[de3$Ey==2001]=de3$symp2[de3$Ey==2001]#2001:2,1,3
de3$Pl.2[de3$Ey==2001]=de3$symp1[de3$Ey==2001]
de3$Pl.3[de3$Ey==2001]=de3$symp3[de3$Ey==2001]
de3$Pl.1[de3$Pl.1>23|de3$Pl.1<0]=NA#recoding to 0-10 scale
de3$Pl.2[de3$Pl.2>23|de3$Pl.2<0]=NA
de3$Pl.3[de3$Pl.3>23|de3$Pl.3<0]=NA
de3$Pl.1[de3$Ey==1997]=(de3$Pl.1[de3$Ey==1997]-1)
de3$Pl.1[de3$Ey==2001]=(de3$Pl.1[de3$Ey==2001]-1)
de3$Pl.2[de3$Ey==1997]=(de3$Pl.2[de3$Ey==1997]-1)
de3$Pl.2[de3$Ey==2001]=(de3$Pl.2[de3$Ey==2001]-1)
de3$Pl.3[de3$Ey==1997]=(de3$Pl.3[de3$Ey==1997]-1)
de3$Pl.3[de3$Ey==2001]=(de3$Pl.3[de3$Ey==2001]-1)
#leader likability:
de3$Ll.1=NA
de3$Ll.2=NA
de3$Ll.3=NA
de3$Ll.4=NA
de3$Ll.5=NA
de3$Ll.6=NA
de3$Ll.1[de3$Ey==1974]=de3$sympl2[de3$Ey==1974]#1974:2,1,3
de3$Ll.2[de3$Ey==1974]=de3$sympl1[de3$Ey==1974]
de3$Ll.3[de3$Ey==1974]=de3$sympl3[de3$Ey==1974]
de3$Ll.1[de3$Ey==1975]=de3$sympl2[de3$Ey==1975]#1975:2,1,3
de3$Ll.2[de3$Ey==1975]=de3$sympl1[de3$Ey==1975]
de3$Ll.3[de3$Ey==1975]=de3$sympl3[de3$Ey==1975]
de3$Ll.1[de3$Ey==1979]=de3$sympl1[de3$Ey==1979]#1979:1,2,3
de3$Ll.2[de3$Ey==1979]=de3$sympl2[de3$Ey==1979]
de3$Ll.3[de3$Ey==1979]=de3$sympl3[de3$Ey==1979]
de3$Ll.1[de3$Ey==1997]=de3$sympl2[de3$Ey==1997]#1997:2,1,3
de3$Ll.2[de3$Ey==1997]=de3$sympl1[de3$Ey==1997]
de3$Ll.3[de3$Ey==1997]=de3$sympl3[de3$Ey==1997]
de3$Ll.1[de3$Ey==2001]=de3$sympl2[de3$Ey==2001]#2001:2,1,3
de3$Ll.2[de3$Ey==2001]=de3$sympl1[de3$Ey==2001]
de3$Ll.3[de3$Ey==2001]=de3$sympl3[de3$Ey==2001]
de3$Ll.1[de3$Ll.1>25|de3$Ll.1<0]=NA#recoding to 0-10 scale
de3$Ll.2[de3$Ll.2>25|de3$Ll.2<0]=NA
de3$Ll.3[de3$Ll.3>25|de3$Ll.3<0]=NA
de3$Ll.1[de3$Ey==1997]=(de3$Ll.1[de3$Ey==1997]-1)
de3$Ll.1[de3$Ey==2001]=(de3$Ll.1[de3$Ey==2001]-1)
# de3$Ll.2[de3$Ey==1997]=(de3$Ll.2[de3$Ey==1997]-1)#already on 0-10scale
# de3$Ll.2[de3$Ey==2001]=(de3$Ll.2[de3$Ey==2001]-1)
de3$Ll.3[de3$Ey==1997]=(de3$Ll.3[de3$Ey==1997]-1)
de3$Ll.3[de3$Ey==2001]=(de3$Ll.3[de3$Ey==2001]-1)
#LRR=Left Right Respondent (voter LR self):
de3$LRR=NA#(no correspondence coding - codebook)
de3$LRR=as.numeric(de3$LRR)
#LRP.i=Left Right Parties:
de3$LRP.1=NA#(no correspondence coding - codebook)
de3$LRP.2=NA
de3$LRP.3=NA
de3$LRP.4=NA
de3$LRP.5=NA
de3$LRP.6=NA
#Elections with LRR and LRP:
de3$LR=0#(no correspondence coding - codebook)
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
de3$EeconS=NA#(no data)
#Elections with EeconS:
de3$Eecon=0#(no data)
#Seats to vote ratios:
de3$P1P2rat=NA
de3$P1P2rat[de3$Ey==1974]=1.05
de3$P1P2rat[de3$Ey==1975]=1.03
de3$P1P2rat[de3$Ey==1979]=1.25
de3$P1P2rat[de3$Ey==1997]=1.80
de3$P1P2rat[de3$Ey==2001]=1.93
#Gallagher Disproportionality measure:
de3$GDM=NA
de3$GDM[de3$Ey==1974]=14.96
de3$GDM[de3$Ey==1975]=15.47
de3$GDM[de3$Ey==1979]=11.58
de3$GDM[de3$Ey==1997]=16.51
de3$GDM[de3$Ey==2001]=17.76
#Party family:
de3$PartyFamilyCode1=60
de3$PartyFamilyCode2=30
de3$PartyFamilyCode3=40
de3$Pf.1=NA
de3$Pf.2=NA
de3$Pf.3=NA
de3$Pf.4=NA
de3$Pf.5=NA
de3$Pf.6=NA
de3$Pf.1[de3$Ey==1974]=de3$PartyFamilyCode2[de3$Ey==1974]#1974:2,1,3
de3$Pf.2[de3$Ey==1974]=de3$PartyFamilyCode1[de3$Ey==1974]
de3$Pf.3[de3$Ey==1974]=de3$PartyFamilyCode3[de3$Ey==1974]
de3$Pf.1[de3$Ey==1975]=de3$PartyFamilyCode2[de3$Ey==1975]#1975:2,1,3
de3$Pf.2[de3$Ey==1975]=de3$PartyFamilyCode1[de3$Ey==1975]
de3$Pf.3[de3$Ey==1975]=de3$PartyFamilyCode3[de3$Ey==1975]
de3$Pf.1[de3$Ey==1979]=de3$PartyFamilyCode1[de3$Ey==1979]#1979:1,2,3
de3$Pf.2[de3$Ey==1979]=de3$PartyFamilyCode2[de3$Ey==1979]
de3$Pf.3[de3$Ey==1979]=de3$PartyFamilyCode3[de3$Ey==1979]
de3$Pf.1[de3$Ey==1997]=de3$PartyFamilyCode2[de3$Ey==1997]#1997:2,1,3
de3$Pf.2[de3$Ey==1997]=de3$PartyFamilyCode1[de3$Ey==1997]
de3$Pf.3[de3$Ey==1997]=de3$PartyFamilyCode3[de3$Ey==1997]
de3$Pf.1[de3$Ey==2001]=de3$PartyFamilyCode2[de3$Ey==2001]#2001:2,1,3
de3$Pf.2[de3$Ey==2001]=de3$PartyFamilyCode1[de3$Ey==2001]
de3$Pf.3[de3$Ey==2001]=de3$PartyFamilyCode3[de3$Ey==2001]
#coding coalition status:
de3$CoalCode=0
#CMPid.i:
de3$CMPid.1=NA#create CMPid:
de3$CMPid.2=NA
de3$CMPid.3=NA
de3$CMPid.4=NA
de3$CMPid.5=NA
de3$CMPid.6=NA
de3$CMPid.1[de3$Ey==1974]=51320#assign CMPid by party size order for parties with likability:
de3$CMPid.2[de3$Ey==1974]=51620
de3$CMPid.3[de3$Ey==1974]=51420
de3$CMPid.1[de3$Ey==1975]=51320
de3$CMPid.2[de3$Ey==1975]=51620
de3$CMPid.3[de3$Ey==1975]=51420
de3$CMPid.1[de3$Ey==1979]=51620
de3$CMPid.2[de3$Ey==1979]=51320
de3$CMPid.3[de3$Ey==1979]=51420
de3$CMPid.1[de3$Ey==2001]=51320
de3$CMPid.2[de3$Ey==2001]=51620
de3$CMPid.3[de3$Ey==2001]=51421
de3$CMPid.1=as.numeric(de3$CMPid.1)#recode as numeric:
de3$CMPid.2=as.numeric(de3$CMPid.2)
de3$CMPid.3=as.numeric(de3$CMPid.3)
de3$CMPid.4=as.numeric(de3$CMPid.4)
de3$CMPid.5=as.numeric(de3$CMPid.5)
de3$CMPid.6=as.numeric(de3$CMPid.6)
#PrePost:
de3$PrePost=as.numeric(NA)
de3$PrePost[de3$Ey==1974]=1
de3$PrePost[de3$Ey==1975]=1
de3$PrePost[de3$Ey==1979]=1
#"Pi"#Party identification:
de3$Pi=NA
de3$Pi[de3$Ey==1974&de3$pid==2]=1#1974:2,1,3
de3$Pi[de3$Ey==1974&de3$pid==1]=2
de3$Pi[de3$Ey==1974&de3$pid==3]=3
de3$Pi[de3$Ey==1975&de3$pid==2]=1#1975:2,1,3
de3$Pi[de3$Ey==1975&de3$pid==1]=2
de3$Pi[de3$Ey==1975&de3$pid==3]=3
de3$Pi[de3$Ey==1979&de3$pid==1]=1#1979:1,2,3
de3$Pi[de3$Ey==1979&de3$pid==2]=2
de3$Pi[de3$Ey==1979&de3$pid==3]=3
de3$Pi[de3$Ey==1997&de3$pid==2]=1#1997:2,1,3
de3$Pi[de3$Ey==1997&de3$pid==1]=2
de3$Pi[de3$Ey==1997&de3$pid==3]=3
de3$Pi[de3$Ey==2001&de3$pid==2]=1#2001:2,1,3
de3$Pi[de3$Ey==2001&de3$pid==1]=2
de3$Pi[de3$Ey==2001&de3$pid==3]=3
#subset:
colnames(de3)
```

```
##   [1] "Ec"               "Ey"               "Rwd"              "study"            "resp"             "sex"              "born"             "Rage"             "married"          "region"           "edu"              "religion"         "churchat"         "egpclass"         "subclass"         "hincome"          "union"            "housing"          "campintr"         "carewon"          "tvradio"          "newspapr"         "camptalk"         "when"             "elecresp"         "ptsresp"          "member"           "pid"              "strength"         "symp1"            "symp2"            "sympl1"           "sympl2"           "lrsp"             "lrp1"             "lrp2"             "lrp3"             "incprcsa"         "incprcsb"         "penssrvs"         "strksprb"         "tupower"          "busnpowr"         "natlview"         "deathpen"         "immgrvw"          "nclrwepn"         "eecview"          "Vt"               "vote"             "rturnout"         "vote1ago"        
##  [53] "typeschl"         "rsincome"         "intrspol"         "tvpoltcs"         "newsppol"         "poltalka"         "symp3"            "sympl3"           "britecon"         "toopwrtu"         "toopwrbb"         "srvsview"         "pricsimp"         "natlimp"          "strksimp"         "wagesimp"         "srvsimp"          "pensnimp"         "eecimp"           "taxesimp"         "commimp"          "public"           "abortion"         "sexmedia"         "compschl"         "wrkrssay"         "nhsspend"         "wlfrben"          "redistrb"         "oppblack"         "eqoppwom"         "unempimp"         "housgimp"         "nsoilimp"         "brdcasts"         "tulaws"           "stifsent"         "nucpind"          "scotass"          "taxsvimp"         "tulawimp"         "lawimp"           "racrlimp"         "symp4"            "sympl4"           "priveduc"         "privmed"          "makejobs"         "rtxspd"           "unemcrim"         "immgrcut"         "nucps2fr"        
## [105] "inglhart"         "britnclr"         "defspend"         "inflimp"          "falksimp"         "defimp"           "govnosay"         "govcomp"          "votintr"          "fairshar"         "richlaw"          "indust4"          "tradvals"         "hlthimp"          "educimp"          "newsattn"         "talkpol1"         "tuntneed"         "privent"          "publcown"         "censor"           "pubmeet"          "gaysex"           "tolerant"         "banparty"         "eec"              "votjbprc"         "votinceq"         "votprnat"         "votecind"         "vottxspd"         "tvnatfrq"         "scotparl"         "symp5"            "sympl5"           "lrp4"             "lrp5"             "kppound"          "impissue"         "Va"               "NP"               "Pl.1"             "Pl.2"             "Pl.3"             "Pl.4"             "Pl.5"             "Pl.6"             "Ll.1"             "Ll.2"             "Ll.3"             "Ll.4"             "Ll.5"            
## [157] "Ll.6"             "LRR"              "LRP.1"            "LRP.2"            "LRP.3"            "LRP.4"            "LRP.5"            "LRP.6"            "LR"               "EeconS"           "Eecon"            "P1P2rat"          "GDM"              "PartyFamilyCode1" "PartyFamilyCode2" "PartyFamilyCode3" "Pf.1"             "Pf.2"             "Pf.3"             "Pf.4"             "Pf.5"             "Pf.6"             "CoalCode"         "CMPid.1"          "CMPid.2"          "CMPid.3"          "CMPid.4"          "CMPid.5"          "CMPid.6"          "PrePost"          "Pi"
```

``` r
de3=de3[,c(1,2,3,145,49,144,146:157,165,158,159:164,167,166,168,169,173:186,8,187)]
colnames(de3)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
de3[colnames(de3)]=sapply(de3[colnames(de3)],as.numeric)


#NETHERLANDS EV de4:----
de4=read_dta("ZA3911_nl_1971-1998.dta")
colnames(de4)
```

```
##  [1] "country"  "year"     "weight1"  "weight2"  "study"    "resp"     "sex"      "born"     "age"      "married"  "urban"    "region"   "edu"      "religion" "churchat" "whohead"  "egpclass" "publicrp" "subclass" "income"   "union"    "ownhouse" "polintr"  "tvuse"    "paperuse" "discussi" "when"     "efficac1" "efficac2" "efficac3" "efficac4" "member"   "pid"      "strength" "symp1"    "symp2"    "symp3"    "symp4"    "symp5"    "symp6"    "symp7"    "symp8"    "symp9"    "sympl1"   "sympl2"   "sympl3"   "sympl4"   "sympl5"   "sympl6"   "sympl7"   "sympl8"   "sympl9"   "lrself"   "lrp1"     "lrp2"     "lrp3"     "lrp4"     "lrp5"     "lrp6"     "lrp7"     "lrp8"     "lrp9"     "retrpers" "retrgen"  "retrempl" "govpolic" "moral1"   "moral2"   "moral4"   "moral3"   "state1"   "state2"   "mpm1"     "mpm4bat"  "author1"  "author2"  "author3"  "author22" "author4"  "author5"  "author6"  "author62" "author7"  "author8"  "author9"  "natissu1" "natissu2" "imp1"     "imp2"     "imp3"    
## [91] "turnout"  "partycho" "recturn"  "recchoic" "incomes"  "incomens"
```

``` r
colnames(de4)[colnames(de4)=="year"]="Ey"#Election Year
de4$Ey=as.numeric(de4$Ey)
de4=de4[de4$Ey %in% c(1986,1994,1998),]#get rid of elections without likability
colnames(de4)[colnames(de4)=="country"]="Ec"#Election Country
de4$Ec=as.numeric(de4$Ec)
colnames(de4)[colnames(de4)=="age"]="Rage"#Respondent Age
de4$Rage=as.numeric(de4$Rage)
de4$Rage[de4$Rage>100]=NA
#Vt#Vote Turnout (0 did not vote; 1 voted)
colnames(de4)[colnames(de4)=="turnout"]="Vt"
de4$Vt[de4$Vt>2]=NA
#"Va"#Vote Alphabetical (here numbers), by vote share:
de4$Va=NA
de4$Va[de4$Ey==1986&de4$partycho==5]=1#1986:5,2,8,3
de4$Va[de4$Ey==1986&de4$partycho==2]=2
de4$Va[de4$Ey==1986&de4$partycho==8]=3
de4$Va[de4$Ey==1986&de4$partycho==3]=4
de4$Va[de4$Ey==1994&de4$partycho==2]=1#1994:2,5,8,3
de4$Va[de4$Ey==1994&de4$partycho==5]=2
de4$Va[de4$Ey==1994&de4$partycho==8]=3
de4$Va[de4$Ey==1994&de4$partycho==3]=4
de4$Va[de4$Ey==1998&de4$partycho==2]=1#1998:2,8,5,3
de4$Va[de4$Ey==1998&de4$partycho==8]=2
de4$Va[de4$Ey==1998&de4$partycho==5]=3
de4$Va[de4$Ey==1998&de4$partycho==3]=4
colnames(de4)[colnames(de4)=="weight2"]="Rwd"##Respondent Weight Demographic
de4$Rwd=as.numeric(de4$Rwd)
de4$Rwd[de4$Rwd==0]=1#missing weight put to neutral weight of 1
#Number of Parties:
de4$NP=NA
de4$NP[de4$Ey==1986]=4
de4$NP[de4$Ey==1994]=4
de4$NP[de4$Ey==1998]=4
#party likability:
de4$Pl.1=NA
de4$Pl.2=NA
de4$Pl.3=NA
de4$Pl.4=NA
de4$Pl.5=NA
de4$Pl.6=NA
# de4$Pl.7=NA
de4$Pl.1[de4$Ey==1986]=de4$symp5[de4$Ey==1986]#1986:5,2,8,3
de4$Pl.2[de4$Ey==1986]=de4$symp2[de4$Ey==1986]
de4$Pl.3[de4$Ey==1986]=de4$symp8[de4$Ey==1986]
de4$Pl.4[de4$Ey==1986]=de4$symp3[de4$Ey==1986]
de4$Pl.1[de4$Ey==1994]=de4$symp2[de4$Ey==1994]#1994:2,5,8,3
de4$Pl.2[de4$Ey==1994]=de4$symp5[de4$Ey==1994]
de4$Pl.3[de4$Ey==1994]=de4$symp8[de4$Ey==1994]
de4$Pl.4[de4$Ey==1994]=de4$symp3[de4$Ey==1994]
de4$Pl.1[de4$Ey==1998]=de4$symp2[de4$Ey==1998]#1998:2,8,5,3
de4$Pl.2[de4$Ey==1998]=de4$symp8[de4$Ey==1998]
de4$Pl.3[de4$Ey==1998]=de4$symp5[de4$Ey==1998]
de4$Pl.4[de4$Ey==1998]=de4$symp3[de4$Ey==1998]
de4$Pl.1[de4$Pl.1>100]=NA#recoding to 0-10 scale
de4$Pl.2[de4$Pl.2>100]=NA
de4$Pl.3[de4$Pl.3>100]=NA
de4$Pl.4[de4$Pl.4>100]=NA
de4$Pl.1=de4$Pl.1/10
de4$Pl.2=de4$Pl.2/10
de4$Pl.3=de4$Pl.3/10
de4$Pl.4=de4$Pl.4/10
#leader likability:
de4$Ll.1=NA
de4$Ll.2=NA
de4$Ll.3=NA
de4$Ll.4=NA
de4$Ll.5=NA
de4$Ll.6=NA
# de4$Ll.7=NA
de4$Ll.1[de4$Ey==1986]=de4$sympl5[de4$Ey==1986]#1986:5,2,8,3
de4$Ll.2[de4$Ey==1986]=de4$sympl2[de4$Ey==1986]
de4$Ll.3[de4$Ey==1986]=de4$sympl8[de4$Ey==1986]
de4$Ll.4[de4$Ey==1986]=de4$sympl3[de4$Ey==1986]
de4$Ll.1[de4$Ey==1994]=de4$sympl2[de4$Ey==1994]#1994:2,5,8,3
de4$Ll.2[de4$Ey==1994]=de4$sympl5[de4$Ey==1994]
de4$Ll.3[de4$Ey==1994]=de4$sympl8[de4$Ey==1994]
de4$Ll.4[de4$Ey==1994]=de4$sympl3[de4$Ey==1994]
de4$Ll.1[de4$Ey==1998]=de4$sympl2[de4$Ey==1998]#1998:2,8,5,3
de4$Ll.2[de4$Ey==1998]=de4$sympl8[de4$Ey==1998]
de4$Ll.3[de4$Ey==1998]=de4$sympl5[de4$Ey==1998]
de4$Ll.4[de4$Ey==1998]=de4$sympl3[de4$Ey==1998]
de4$Ll.1[de4$Ll.1>100]=NA#recoding to 0-10 scale
de4$Ll.2[de4$Ll.2>100]=NA
de4$Ll.3[de4$Ll.3>100]=NA
de4$Ll.4[de4$Ll.4>100]=NA
de4$Ll.1=de4$Ll.1/10
de4$Ll.2=de4$Ll.2/10
de4$Ll.3=de4$Ll.3/10
de4$Ll.4=de4$Ll.4/10
#LRR=Left Right Respondent (voter LR self):
colnames(de4)[colnames(de4)=="lrself"]="LRR"
de4$LRR=(de4$LRR-1)*10/9#recoding to 0-10 scale
de4$LRR[de4$LRR>10]=NA
de4$LRR=as.numeric(de4$LRR)
#LRP.i=Left Right Parties:
de4$LRP.1=NA
de4$LRP.2=NA
de4$LRP.3=NA
de4$LRP.4=NA
de4$LRP.5=NA
de4$LRP.6=NA
# de4$LRP.7=NA
de4$LRP.1[de4$Ey==1986]=de4$lrp5[de4$Ey==1986]#1986:5,2,8,3
de4$LRP.2[de4$Ey==1986]=de4$lrp2[de4$Ey==1986]
de4$LRP.3[de4$Ey==1986]=de4$lrp8[de4$Ey==1986]
de4$LRP.4[de4$Ey==1986]=de4$lrp3[de4$Ey==1986]
de4$LRP.1[de4$Ey==1994]=de4$lrp2[de4$Ey==1994]#1994:2,5,8,3
de4$LRP.2[de4$Ey==1994]=de4$lrp5[de4$Ey==1994]
de4$LRP.3[de4$Ey==1994]=de4$lrp8[de4$Ey==1994]
de4$LRP.4[de4$Ey==1994]=de4$lrp3[de4$Ey==1994]
de4$LRP.1[de4$Ey==1998]=de4$lrp2[de4$Ey==1998]#1998:2,8,5,3
de4$LRP.2[de4$Ey==1998]=de4$lrp8[de4$Ey==1998]
de4$LRP.3[de4$Ey==1998]=de4$lrp5[de4$Ey==1998]
de4$LRP.4[de4$Ey==1998]=de4$lrp3[de4$Ey==1998]
de4$LRP.1=(de4$LRP.1-1)*10/9#recoding to 0-10 scale
de4$LRP.1[de4$LRP.1>10]=NA
de4$LRP.2=(de4$LRP.2-1)*10/9
de4$LRP.2[de4$LRP.2>10]=NA
de4$LRP.3=(de4$LRP.3-1)*10/9
de4$LRP.3[de4$LRP.3>10]=NA
de4$LRP.4=(de4$LRP.4-1)*10/9
de4$LRP.4[de4$LRP.4>10]=NA
de4$LRP.5=(de4$LRP.5-1)*10/9
de4$LRP.5[de4$LRP.5>10]=NA
de4$LRP.6=(de4$LRP.6-1)*10/9
de4$LRP.6[de4$LRP.6>10]=NA
#Elections with LRR and LRP:
de4$LR=NA
de4$LR[de4$Ey==1986]=1
de4$LR[de4$Ey==1994]=1
de4$LR[de4$Ey==1998]=1
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
colnames(de4)[colnames(de4)=="economy1"]="EeconS"
de4$EeconS=NA#(no data)
#Elections with EeconS:
de4$Eecon=0#(no data)
#Seats to vote ratios:
de4$P1P2rat=NA
de4$P1P2rat[de4$Ey==1986]=1.00
de4$P1P2rat[de4$Ey==1994]=1.01
de4$P1P2rat[de4$Ey==1998]=1.01
#Gallagher Disproportionality measure:
de4$GDM=NA
de4$GDM[de4$Ey==1986]=1.67
de4$GDM[de4$Ey==1994]=1.08
de4$GDM[de4$Ey==1998]=1.28
#Party family:
de4$PartyFamilyCode2=30
de4$PartyFamilyCode3=40
de4$PartyFamilyCode5=50
de4$PartyFamilyCode8=40
de4$Pf.1=NA
de4$Pf.2=NA
de4$Pf.3=NA
de4$Pf.4=NA
de4$Pf.5=NA
de4$Pf.6=NA
# de4$Pf.7=NA
de4$Pf.1[de4$Ey==1986]=de4$PartyFamilyCode5[de4$Ey==1986]#1986:5,2,8,3
de4$Pf.2[de4$Ey==1986]=de4$PartyFamilyCode2[de4$Ey==1986]
de4$Pf.3[de4$Ey==1986]=de4$PartyFamilyCode8[de4$Ey==1986]
de4$Pf.4[de4$Ey==1986]=de4$PartyFamilyCode3[de4$Ey==1986]
de4$Pf.1[de4$Ey==1994]=de4$PartyFamilyCode2[de4$Ey==1994]#1994:2,5,8,3
de4$Pf.2[de4$Ey==1994]=de4$PartyFamilyCode5[de4$Ey==1994]
de4$Pf.3[de4$Ey==1994]=de4$PartyFamilyCode8[de4$Ey==1994]
de4$Pf.4[de4$Ey==1994]=de4$PartyFamilyCode3[de4$Ey==1994]
de4$Pf.1[de4$Ey==1998]=de4$PartyFamilyCode2[de4$Ey==1998]#1998:2,8,5,3
de4$Pf.2[de4$Ey==1998]=de4$PartyFamilyCode8[de4$Ey==1998]
de4$Pf.3[de4$Ey==1998]=de4$PartyFamilyCode5[de4$Ey==1998]
de4$Pf.4[de4$Ey==1998]=de4$PartyFamilyCode3[de4$Ey==1998]
#coding coalition status:
de4$CoalCode=0
#CMPid.i:
de4$CMPid.1=NA#create CMPid:
de4$CMPid.2=NA
de4$CMPid.3=NA
de4$CMPid.4=NA
de4$CMPid.5=NA
de4$CMPid.6=NA
de4$CMPid.1[de4$Ey==1986]=22521#assign CMPid by party size order for parties with likability:
de4$CMPid.2[de4$Ey==1986]=22320
de4$CMPid.3[de4$Ey==1986]=22420
de4$CMPid.4[de4$Ey==1986]=22330
de4$CMPid.1=as.numeric(de4$CMPid.1)#recode as numeric:
de4$CMPid.2=as.numeric(de4$CMPid.2)
de4$CMPid.3=as.numeric(de4$CMPid.3)
de4$CMPid.4=as.numeric(de4$CMPid.4)
de4$CMPid.5=as.numeric(de4$CMPid.5)
de4$CMPid.6=as.numeric(de4$CMPid.6)
#PrePost:
de4$PrePost=as.numeric(NA)
de4$PrePost[de4$Ey==1986]=3
#"Pi"#Party identification:
de4$Pi=NA
de4$Pi[de4$Ey==1986&de4$pid==5]=1#1986:5,2,8,3
de4$Pi[de4$Ey==1986&de4$pid==2]=2
de4$Pi[de4$Ey==1986&de4$pid==8]=3
de4$Pi[de4$Ey==1986&de4$pid==3]=4
de4$Pi[de4$Ey==1994&de4$pid==2]=1#1994:2,5,8,3
de4$Pi[de4$Ey==1994&de4$pid==5]=2
de4$Pi[de4$Ey==1994&de4$pid==8]=3
de4$Pi[de4$Ey==1994&de4$pid==3]=4
de4$Pi[de4$Ey==1998&de4$pid==2]=1#1998:2,8,5,3
de4$Pi[de4$Ey==1998&de4$pid==8]=2
de4$Pi[de4$Ey==1998&de4$pid==5]=3
de4$Pi[de4$Ey==1998&de4$pid==3]=4
#subset:
colnames(de4)
```

```
##   [1] "Ec"               "Ey"               "weight1"          "Rwd"              "study"            "resp"             "sex"              "born"             "Rage"             "married"          "urban"            "region"           "edu"              "religion"         "churchat"         "whohead"          "egpclass"         "publicrp"         "subclass"         "income"           "union"            "ownhouse"         "polintr"          "tvuse"            "paperuse"         "discussi"         "when"             "efficac1"         "efficac2"         "efficac3"         "efficac4"         "member"           "pid"              "strength"         "symp1"            "symp2"            "symp3"            "symp4"            "symp5"            "symp6"            "symp7"            "symp8"            "symp9"            "sympl1"           "sympl2"           "sympl3"           "sympl4"           "sympl5"           "sympl6"           "sympl7"           "sympl8"           "sympl9"          
##  [53] "LRR"              "lrp1"             "lrp2"             "lrp3"             "lrp4"             "lrp5"             "lrp6"             "lrp7"             "lrp8"             "lrp9"             "retrpers"         "retrgen"          "retrempl"         "govpolic"         "moral1"           "moral2"           "moral4"           "moral3"           "state1"           "state2"           "mpm1"             "mpm4bat"          "author1"          "author2"          "author3"          "author22"         "author4"          "author5"          "author6"          "author62"         "author7"          "author8"          "author9"          "natissu1"         "natissu2"         "imp1"             "imp2"             "imp3"             "Vt"               "partycho"         "recturn"          "recchoic"         "incomes"          "incomens"         "Va"               "NP"               "Pl.1"             "Pl.2"             "Pl.3"             "Pl.4"             "Pl.5"             "Pl.6"            
## [105] "Ll.1"             "Ll.2"             "Ll.3"             "Ll.4"             "Ll.5"             "Ll.6"             "LRP.1"            "LRP.2"            "LRP.3"            "LRP.4"            "LRP.5"            "LRP.6"            "LR"               "EeconS"           "Eecon"            "P1P2rat"          "GDM"              "PartyFamilyCode2" "PartyFamilyCode3" "PartyFamilyCode5" "PartyFamilyCode8" "Pf.1"             "Pf.2"             "Pf.3"             "Pf.4"             "Pf.5"             "Pf.6"             "CoalCode"         "CMPid.1"          "CMPid.2"          "CMPid.3"          "CMPid.4"          "CMPid.5"          "CMPid.6"          "PrePost"          "Pi"
```

``` r
de4=de4[,c(1,2,4,98,91,97,99:110,117,53,111:116,119,118,120,121,126:139,9,140)]
colnames(de4)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
de4[colnames(de4)]=sapply(de4[colnames(de4)],as.numeric)


#NORWAY EV de5:----
de5=read_dta("ZA3911_no_1965-1997.dta")
colnames(de5)
```

```
##   [1] "country"  "year"     "weight"   "idnr"     "sex"      "born"     "age"      "married"  "urban"    "region"   "edu"      "church"   "work"     "egpclass" "egpsub"   "public"   "subclass" "union"    "income3"  "teetotal" "polint"   "carewon"  "discuss"  "when"     "efficac1" "efficac2" "efficac3" "efficac4" "member"   "pid"      "strength" "strengta" "sympsoc"  "symplab"  "symplib"  "sympchr"  "sympc"    "sympcons" "sympprog" "sympsocl" "symplabl" "symplibl" "sympchrl" "sympcl"   "sympconl" "sympprol" "lrsp"     "lrsoc"    "lrlab"    "lrlib"    "lrchr"    "lrc"      "lrcons"   "lrprog"   "econom1"  "econom2"  "econom3"  "unemploy" "blame1"   "blame1a"  "blame2"   "blame2a"  "hv20"     "sol20"    "miljo20"  "moral20"  "mpm"      "opind1"   "opind2"   "opind3"   "opind4"   "opind5"   "opind6"   "opind7"   "opind8"   "opind9"   "opind10"  "opind11"  "opind12"  "opind13"  "opind14"  "soli1"    "soli2"    "soli3"    "soli4"    "soli5"    "soli6"    "soli7"    "soli8"    "soli9"   
##  [91] "soli10"   "soli11"   "soli12"   "soli13"   "soli14"   "vern1"    "vern2"    "vern3"    "vern4"    "vern5"    "vern6"    "vern7"    "vern8"    "vern9"    "vern10"   "vern11"   "vern12"   "vern13"   "moral1"   "moral2"   "moral3"   "moral4"   "moral5"   "moral6"   "moral7"   "moral8"   "moral9"   "moral10"  "moral11"  "moral12"  "moral13"  "moral14"  "nato"     "eu"       "aid"      "imp1"     "imp2"     "turnout"  "choice"   "recall"
```

``` r
colnames(de5)[colnames(de5)=="year"]="Ey"#Election Year
de5$Ey=as.numeric(de5$Ey)
de5=de5[de5$Ey>=1981,]#get rid of elections without likability
colnames(de5)[colnames(de5)=="country"]="Ec"#Election Country
de5$Ec=as.numeric(de5$Ec)
colnames(de5)[colnames(de5)=="age"]="Rage"#Respondent Age
de5$Rage=as.numeric(de5$Rage)
de5$Rage[de5$Rage>100]=NA
#Vt#Vote Turnout (0 did not vote; 1 voted)
colnames(de5)[colnames(de5)=="turnout"]="Vt"
de5$Vt[de5$Vt>2]=NA
de5$Vt[de5$Vt==2]=0
#"Va"#Vote Alphabetical (here numbers), by vote share:
de5$Va=NA
de5$Va[de5$Ey==1981&de5$choice==3]=1#1981:3,8,5,6,2,9
de5$Va[de5$Ey==1981&de5$choice==8]=2
de5$Va[de5$Ey==1981&de5$choice==5]=3
de5$Va[de5$Ey==1981&de5$choice==6]=4
de5$Va[de5$Ey==1981&de5$choice==2]=5
de5$Va[de5$Ey==1981&de5$choice==9]=6
de5$Va[de5$Ey==1985&de5$choice==3]=1#1985:3,8,5,6,2,9
de5$Va[de5$Ey==1985&de5$choice==8]=2
de5$Va[de5$Ey==1985&de5$choice==5]=3
de5$Va[de5$Ey==1985&de5$choice==6]=4
de5$Va[de5$Ey==1985&de5$choice==2]=5
de5$Va[de5$Ey==1985&de5$choice==9]=6
de5$Va[de5$Ey==1989&de5$choice==3]=1#1989:3,8,9,2,5,6
de5$Va[de5$Ey==1989&de5$choice==8]=2
de5$Va[de5$Ey==1989&de5$choice==9]=3
de5$Va[de5$Ey==1989&de5$choice==2]=4
de5$Va[de5$Ey==1989&de5$choice==5]=5
de5$Va[de5$Ey==1989&de5$choice==6]=6
de5$Va[de5$Ey==1993&de5$choice==3]=1#1993:3,6,8,2,5,9
de5$Va[de5$Ey==1993&de5$choice==6]=2
de5$Va[de5$Ey==1993&de5$choice==8]=3
de5$Va[de5$Ey==1993&de5$choice==2]=4
de5$Va[de5$Ey==1993&de5$choice==5]=5
de5$Va[de5$Ey==1993&de5$choice==9]=6
de5$Va[de5$Ey==1997&de5$choice==3]=1#1997:3,9,5,8,6,2
de5$Va[de5$Ey==1997&de5$choice==9]=2
de5$Va[de5$Ey==1997&de5$choice==5]=3
de5$Va[de5$Ey==1997&de5$choice==8]=4
de5$Va[de5$Ey==1997&de5$choice==6]=5
de5$Va[de5$Ey==1997&de5$choice==2]=6
colnames(de5)[colnames(de5)=="weight"]="Rwd"#Respondent Weight Demographic (there's no weight, all entries are 1)
de5$Rwd=as.numeric(de5$Rwd)#tehy are all 1, there is no information on weights
summary(de5$Rwd)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       1       1       1       1       1       1
```

``` r
#Number of Parties:
de5$NP=NA
de5$NP[de5$Ey==1981]=6
de5$NP[de5$Ey==1985]=6
de5$NP[de5$Ey==1989]=6
de5$NP[de5$Ey==1993]=6
de5$NP[de5$Ey==1997]=6
#party likability:
de5$Pl.1=NA
de5$Pl.2=NA
de5$Pl.3=NA
de5$Pl.4=NA
de5$Pl.5=NA
de5$Pl.6=NA
# de5$Pl.7=NA
de5$Pl.1[de5$Ey==1981]=de5$symplab[de5$Ey==1981]#1981:3,8,5,6,2,9
de5$Pl.2[de5$Ey==1981]=de5$sympcons[de5$Ey==1981]
de5$Pl.3[de5$Ey==1981]=de5$sympchr[de5$Ey==1981]
de5$Pl.4[de5$Ey==1981]=de5$sympc[de5$Ey==1981]
de5$Pl.5[de5$Ey==1981]=de5$sympsoc[de5$Ey==1981]
de5$Pl.6[de5$Ey==1981]=de5$sympprog[de5$Ey==1981]
de5$Pl.1[de5$Ey==1985]=de5$symplab[de5$Ey==1985]#1985:3,8,5,6,2,9
de5$Pl.2[de5$Ey==1985]=de5$sympcons[de5$Ey==1985]
de5$Pl.3[de5$Ey==1985]=de5$sympchr[de5$Ey==1985]
de5$Pl.4[de5$Ey==1985]=de5$sympc[de5$Ey==1985]
de5$Pl.5[de5$Ey==1985]=de5$sympsoc[de5$Ey==1985]
de5$Pl.6[de5$Ey==1985]=de5$sympprog[de5$Ey==1985]
de5$Pl.1[de5$Ey==1989]=de5$symplab[de5$Ey==1989]#1989:3,8,9,2,5,6
de5$Pl.2[de5$Ey==1989]=de5$sympcons[de5$Ey==1989]
de5$Pl.3[de5$Ey==1989]=de5$sympprog[de5$Ey==1989]
de5$Pl.4[de5$Ey==1989]=de5$sympsoc[de5$Ey==1989]
de5$Pl.5[de5$Ey==1989]=de5$sympchr[de5$Ey==1989]
de5$Pl.6[de5$Ey==1989]=de5$sympc[de5$Ey==1989]
de5$Pl.1[de5$Ey==1993]=de5$symplab[de5$Ey==1993]#1993:3,6,8,2,5,9
de5$Pl.2[de5$Ey==1993]=de5$sympc[de5$Ey==1993]
de5$Pl.3[de5$Ey==1993]=de5$sympcons[de5$Ey==1993]
de5$Pl.4[de5$Ey==1993]=de5$sympsoc[de5$Ey==1993]
de5$Pl.5[de5$Ey==1993]=de5$sympchr[de5$Ey==1993]
de5$Pl.6[de5$Ey==1993]=de5$sympprog[de5$Ey==1993]
de5$Pl.1[de5$Ey==1997]=de5$symplab[de5$Ey==1997]#1997:3,9,5,8,6,2
de5$Pl.2[de5$Ey==1997]=de5$sympprog[de5$Ey==1997]
de5$Pl.3[de5$Ey==1997]=de5$sympchr[de5$Ey==1997]
de5$Pl.4[de5$Ey==1997]=de5$sympcons[de5$Ey==1997]
de5$Pl.5[de5$Ey==1997]=de5$sympc[de5$Ey==1997]
de5$Pl.6[de5$Ey==1997]=de5$sympsoc[de5$Ey==1997]
de5$Pl.1=de5$Pl.1/10#recoding to 0-10 scale
de5$Pl.2=de5$Pl.2/10
de5$Pl.3=de5$Pl.3/10
de5$Pl.4=de5$Pl.4/10
de5$Pl.5=de5$Pl.5/10
de5$Pl.6=de5$Pl.6/10
#leader likability:
de5$Ll.1=NA
de5$Ll.2=NA
de5$Ll.3=NA
de5$Ll.4=NA
de5$Ll.5=NA
de5$Ll.6=NA
# de5$Ll.7=NA
de5$Ll.1[de5$Ey==1981]=de5$symplabl[de5$Ey==1981]#1981:3,8,5,6,2,9
de5$Ll.2[de5$Ey==1981]=de5$sympconl[de5$Ey==1981]
de5$Ll.3[de5$Ey==1981]=de5$sympchrl[de5$Ey==1981]
de5$Ll.4[de5$Ey==1981]=de5$sympcl[de5$Ey==1981]
de5$Ll.5[de5$Ey==1981]=de5$sympsocl[de5$Ey==1981]
de5$Ll.6[de5$Ey==1981]=de5$sympprol[de5$Ey==1981]
de5$Ll.1[de5$Ey==1985]=de5$symplabl[de5$Ey==1985]#1985:3,8,5,6,2,9
de5$Ll.2[de5$Ey==1985]=de5$sympconl[de5$Ey==1985]
de5$Ll.3[de5$Ey==1985]=de5$sympchrl[de5$Ey==1985]
de5$Ll.4[de5$Ey==1985]=de5$sympcl[de5$Ey==1985]
de5$Ll.5[de5$Ey==1985]=de5$sympsocl[de5$Ey==1985]
de5$Ll.6[de5$Ey==1985]=de5$sympprol[de5$Ey==1985]
de5$Ll.1[de5$Ey==1989]=de5$symplabl[de5$Ey==1989]#1989:3,8,9,2,5,6
de5$Ll.2[de5$Ey==1989]=de5$sympconl[de5$Ey==1989]
de5$Ll.3[de5$Ey==1989]=de5$sympprol[de5$Ey==1989]
de5$Ll.4[de5$Ey==1989]=de5$sympsocl[de5$Ey==1989]
de5$Ll.5[de5$Ey==1989]=de5$sympchrl[de5$Ey==1989]
de5$Ll.6[de5$Ey==1989]=de5$sympcl[de5$Ey==1989]
de5$Ll.1[de5$Ey==1993]=de5$symplabl[de5$Ey==1993]#1993:3,6,8,2,5,9
de5$Ll.2[de5$Ey==1993]=de5$sympcl[de5$Ey==1993]
de5$Ll.3[de5$Ey==1993]=de5$sympconl[de5$Ey==1993]
de5$Ll.4[de5$Ey==1993]=de5$sympsocl[de5$Ey==1993]
de5$Ll.5[de5$Ey==1993]=de5$sympchrl[de5$Ey==1993]
de5$Ll.6[de5$Ey==1993]=de5$sympprol[de5$Ey==1993]
de5$Ll.1[de5$Ey==1997]=de5$symplabl[de5$Ey==1997]#1997:3,9,5,8,6,2
de5$Ll.2[de5$Ey==1997]=de5$sympprol[de5$Ey==1997]
de5$Ll.3[de5$Ey==1997]=de5$sympchrl[de5$Ey==1997]
de5$Ll.4[de5$Ey==1997]=de5$sympconl[de5$Ey==1997]
de5$Ll.5[de5$Ey==1997]=de5$sympcl[de5$Ey==1997]
de5$Ll.6[de5$Ey==1997]=de5$sympsocl[de5$Ey==1997]
de5$Ll.1=de5$Ll.1/10#recoding to 0-10 scale
de5$Ll.2=de5$Ll.2/10
de5$Ll.3=de5$Ll.3/10
de5$Ll.4=de5$Ll.4/10
de5$Ll.5=de5$Ll.5/10
de5$Ll.6=de5$Ll.6/10
#LRR=Left Right Respondent (voter LR self):
colnames(de5)[colnames(de5)=="lrsp"]="LRR"
de5$LRR=as.numeric(de5$LRR)
#recoding to 0-10 scale: already 0-10 scale
#LRP.i=Left Right Parties:
de5$LRP.1=NA
de5$LRP.2=NA
de5$LRP.3=NA
de5$LRP.4=NA
de5$LRP.5=NA
de5$LRP.6=NA
# de5$LRP.7=NA
de5$LRP.1[de5$Ey==1981]=de5$lrlab[de5$Ey==1981]#1981:3,8,5,6,2,9
de5$LRP.2[de5$Ey==1981]=de5$lrcons[de5$Ey==1981]
de5$LRP.3[de5$Ey==1981]=de5$lrchr[de5$Ey==1981]
de5$LRP.4[de5$Ey==1981]=de5$lrc[de5$Ey==1981]
de5$LRP.5[de5$Ey==1981]=de5$lrsoc[de5$Ey==1981]
de5$LRP.6[de5$Ey==1981]=de5$lrprog[de5$Ey==1981]
de5$LRP.1[de5$Ey==1985]=de5$lrlab[de5$Ey==1985]#1985:3,8,5,6,2,9
de5$LRP.2[de5$Ey==1985]=de5$lrcons[de5$Ey==1985]
de5$LRP.3[de5$Ey==1985]=de5$lrchr[de5$Ey==1985]
de5$LRP.4[de5$Ey==1985]=de5$lrc[de5$Ey==1985]
de5$LRP.5[de5$Ey==1985]=de5$lrsoc[de5$Ey==1985]
de5$LRP.6[de5$Ey==1985]=de5$lrprog[de5$Ey==1985]
de5$LRP.1[de5$Ey==1989]=de5$lrlab[de5$Ey==1989]#1989:3,8,9,2,5,6
de5$LRP.2[de5$Ey==1989]=de5$lrcons[de5$Ey==1989]
de5$LRP.3[de5$Ey==1989]=de5$lrprog[de5$Ey==1989]
de5$LRP.4[de5$Ey==1989]=de5$lrsoc[de5$Ey==1989]
de5$LRP.5[de5$Ey==1989]=de5$lrchr[de5$Ey==1989]
de5$LRP.6[de5$Ey==1989]=de5$lrc[de5$Ey==1989]
de5$LRP.1[de5$Ey==1993]=de5$lrlab[de5$Ey==1993]#1993:3,6,8,2,5,9
de5$LRP.2[de5$Ey==1993]=de5$lrc[de5$Ey==1993]
de5$LRP.3[de5$Ey==1993]=de5$lrcons[de5$Ey==1993]
de5$LRP.4[de5$Ey==1993]=de5$lrsoc[de5$Ey==1993]
de5$LRP.5[de5$Ey==1993]=de5$lrchr[de5$Ey==1993]
de5$LRP.6[de5$Ey==1993]=de5$lrprog[de5$Ey==1993]
de5$LRP.1[de5$Ey==1997]=de5$lrlab[de5$Ey==1997]#1997:3,9,5,8,6,2
de5$LRP.2[de5$Ey==1997]=de5$lrprog[de5$Ey==1997]
de5$LRP.3[de5$Ey==1997]=de5$lrchr[de5$Ey==1997]
de5$LRP.4[de5$Ey==1997]=de5$lrcons[de5$Ey==1997]
de5$LRP.5[de5$Ey==1997]=de5$lrc[de5$Ey==1997]
de5$LRP.6[de5$Ey==1997]=de5$lrsoc[de5$Ey==1997]
#Elections with LRR and LRP:
de5$LR=NA
de5$LR[de5$Ey==1981]=1
de5$LR[de5$Ey==1985]=1
de5$LR[de5$Ey==1989]=1
de5$LR[de5$Ey==1993]=1
de5$LR[de5$Ey==1997]=1
#recoding to 0-10 scale: already 0-10 scale
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
# 1. MUCH BETTER                 
# 2. SOMEWHAT BETTER     
# 3. STAYED THE SAME              
# 4. SOMEWHAT WORSE
# 5. MUCH WORSE
colnames(de5)[colnames(de5)=="econom3"]="EeconS"
#recode EeconS from EV scale
# 1. GOTTEN BETTER c(1,2,3,4,5)
# 5. GOTTEN WORSE 
# to TEV scale, noting that the TEV used the conversion scale below for same elections:
# 0. Negative evaluation c(0, 0.25, 0.5, 0.75, 1)
# 1. Positive evaluation
de5$EeconS[de5$EeconS==1]=1
de5$EeconS[de5$EeconS==2]=0.75
de5$EeconS[de5$EeconS==3]=0.5
de5$EeconS[de5$EeconS==4]=0.25
de5$EeconS[de5$EeconS==5]=0
#Elections with EeconS:
de5$Eecon=NA
de5$Eecon[de5$Ey==1981]=0
de5$Eecon[de5$Ey==1985]=1
de5$Eecon[de5$Ey==1989]=1
de5$Eecon[de5$Ey==1993]=1
de5$Eecon[de5$Ey==1997]=1
#Seats to vote ratios:
de5$P1P2rat=NA
de5$P1P2rat[de5$Ey==1981]=1.06
de5$P1P2rat[de5$Ey==1985]=1.06
de5$P1P2rat[de5$Ey==1989]=1.10
de5$P1P2rat[de5$Ey==1993]=0.95
de5$P1P2rat[de5$Ey==1997]=1.14
#Gallagher Disproportionality measure:
de5$GDM=NA
de5$GDM[de5$Ey==1981]=4.94
de5$GDM[de5$Ey==1985]=4.75
de5$GDM[de5$Ey==1989]=3.67
de5$GDM[de5$Ey==1993]=3.95
de5$GDM[de5$Ey==1997]=3.44
#Party family:
de5$PartyFamilyCode2=20#Sosialistisk Folkeparti (Socialist People’s Party)
de5$PartyFamilyCode3=30#Det norske Arbeiderparti (Norwegian Labour Party)
de5$PartyFamilyCode5=50#Kristelig Folkeparti (Christian People’s Party)
de5$PartyFamilyCode6=80#Senterpartiet (Centre Party)
de5$PartyFamilyCode8=60#Høyre (Conservative Party)
de5$PartyFamilyCode9=70#Fremskrittspartiet (Progress Party)
# 0            rv
# 1           nkp
# 2            sv
# 3           dna
# 4             v
# 5           Krf
# 6            Sp
# 7           dlf
# 8             h
# 9      Frp(ALP)
de5$Pf.1=NA
de5$Pf.2=NA
de5$Pf.3=NA
de5$Pf.4=NA
de5$Pf.5=NA
de5$Pf.6=NA
# de5$Pf.7=NA
de5$Pf.1[de5$Ey==1981]=de5$PartyFamilyCode3[de5$Ey==1981]#1981:3,8,5,6,2,9
de5$Pf.2[de5$Ey==1981]=de5$PartyFamilyCode8[de5$Ey==1981]
de5$Pf.3[de5$Ey==1981]=de5$PartyFamilyCode5[de5$Ey==1981]
de5$Pf.4[de5$Ey==1981]=de5$PartyFamilyCode6[de5$Ey==1981]
de5$Pf.5[de5$Ey==1981]=de5$PartyFamilyCode2[de5$Ey==1981]
de5$Pf.6[de5$Ey==1981]=de5$PartyFamilyCode9[de5$Ey==1981]
de5$Pf.1[de5$Ey==1985]=de5$PartyFamilyCode3[de5$Ey==1985]#1985:3,8,5,6,2,9
de5$Pf.2[de5$Ey==1985]=de5$PartyFamilyCode8[de5$Ey==1985]
de5$Pf.3[de5$Ey==1985]=de5$PartyFamilyCode5[de5$Ey==1985]
de5$Pf.4[de5$Ey==1985]=de5$PartyFamilyCode6[de5$Ey==1985]
de5$Pf.5[de5$Ey==1985]=de5$PartyFamilyCode2[de5$Ey==1985]
de5$Pf.6[de5$Ey==1985]=de5$PartyFamilyCode9[de5$Ey==1985]
de5$Pf.1[de5$Ey==1989]=de5$PartyFamilyCode3[de5$Ey==1989]#1989:3,8,9,2,5,6
de5$Pf.2[de5$Ey==1989]=de5$PartyFamilyCode8[de5$Ey==1989]
de5$Pf.3[de5$Ey==1989]=de5$PartyFamilyCode9[de5$Ey==1989]
de5$Pf.4[de5$Ey==1989]=de5$PartyFamilyCode2[de5$Ey==1989]
de5$Pf.5[de5$Ey==1989]=de5$PartyFamilyCode5[de5$Ey==1989]
de5$Pf.6[de5$Ey==1989]=de5$PartyFamilyCode6[de5$Ey==1989]
de5$Pf.1[de5$Ey==1993]=de5$PartyFamilyCode3[de5$Ey==1993]#1993:3,6,8,2,5,9
de5$Pf.2[de5$Ey==1993]=de5$PartyFamilyCode6[de5$Ey==1993]
de5$Pf.3[de5$Ey==1993]=de5$PartyFamilyCode8[de5$Ey==1993]
de5$Pf.4[de5$Ey==1993]=de5$PartyFamilyCode2[de5$Ey==1993]
de5$Pf.5[de5$Ey==1993]=de5$PartyFamilyCode5[de5$Ey==1993]
de5$Pf.6[de5$Ey==1993]=de5$PartyFamilyCode9[de5$Ey==1993]
de5$Pf.1[de5$Ey==1997]=de5$PartyFamilyCode3[de5$Ey==1997]#1997:3,9,5,8,6,2
de5$Pf.2[de5$Ey==1997]=de5$PartyFamilyCode9[de5$Ey==1997]
de5$Pf.3[de5$Ey==1997]=de5$PartyFamilyCode5[de5$Ey==1997]
de5$Pf.4[de5$Ey==1997]=de5$PartyFamilyCode8[de5$Ey==1997]
de5$Pf.5[de5$Ey==1997]=de5$PartyFamilyCode6[de5$Ey==1997]
de5$Pf.6[de5$Ey==1997]=de5$PartyFamilyCode2[de5$Ey==1997]
#coding coalition status:
de5$CoalCode=0
#CMPid.i:
de5$CMPid.1=NA#create CMPid:
de5$CMPid.2=NA
de5$CMPid.3=NA
de5$CMPid.4=NA
de5$CMPid.5=NA
de5$CMPid.6=NA
de5$CMPid.1=as.numeric(de5$CMPid.1)#recode as numeric:
de5$CMPid.2=as.numeric(de5$CMPid.2)
de5$CMPid.3=as.numeric(de5$CMPid.3)
de5$CMPid.4=as.numeric(de5$CMPid.4)
de5$CMPid.5=as.numeric(de5$CMPid.5)
de5$CMPid.6=as.numeric(de5$CMPid.6)
#PrePost:
de5$PrePost=as.numeric(NA)
#"Pi"#Party identification:
de5$Pi=NA
de5$Pi[de5$Ey==1981&de5$pid==3]=1#1981:3,8,5,6,2,9
de5$Pi[de5$Ey==1981&de5$pid==8]=2
de5$Pi[de5$Ey==1981&de5$pid==5]=3
de5$Pi[de5$Ey==1981&de5$pid==6]=4
de5$Pi[de5$Ey==1981&de5$pid==2]=5
de5$Pi[de5$Ey==1981&de5$pid==9]=6
de5$Pi[de5$Ey==1985&de5$pid==3]=1#1985:3,8,5,6,2,9
de5$Pi[de5$Ey==1985&de5$pid==8]=2
de5$Pi[de5$Ey==1985&de5$pid==5]=3
de5$Pi[de5$Ey==1985&de5$pid==6]=4
de5$Pi[de5$Ey==1985&de5$pid==2]=5
de5$Pi[de5$Ey==1985&de5$pid==9]=6
de5$Pi[de5$Ey==1989&de5$pid==3]=1#1989:3,8,9,2,5,6
de5$Pi[de5$Ey==1989&de5$pid==8]=2
de5$Pi[de5$Ey==1989&de5$pid==9]=3
de5$Pi[de5$Ey==1989&de5$pid==2]=4
de5$Pi[de5$Ey==1989&de5$pid==5]=5
de5$Pi[de5$Ey==1989&de5$pid==6]=6
de5$Pi[de5$Ey==1993&de5$pid==3]=1#1993:3,6,8,2,5,9
de5$Pi[de5$Ey==1993&de5$pid==6]=2
de5$Pi[de5$Ey==1993&de5$pid==8]=3
de5$Pi[de5$Ey==1993&de5$pid==2]=4
de5$Pi[de5$Ey==1993&de5$pid==5]=5
de5$Pi[de5$Ey==1993&de5$pid==9]=6
de5$Pi[de5$Ey==1997&de5$pid==3]=1#1997:3,9,5,8,6,2
de5$Pi[de5$Ey==1997&de5$pid==9]=2
de5$Pi[de5$Ey==1997&de5$pid==5]=3
de5$Pi[de5$Ey==1997&de5$pid==8]=4
de5$Pi[de5$Ey==1997&de5$pid==6]=5
de5$Pi[de5$Ey==1997&de5$pid==2]=6
#subset:
colnames(de5)
```

```
##   [1] "Ec"               "Ey"               "Rwd"              "idnr"             "sex"              "born"             "Rage"             "married"          "urban"            "region"           "edu"              "church"           "work"             "egpclass"         "egpsub"           "public"           "subclass"         "union"            "income3"          "teetotal"         "polint"           "carewon"          "discuss"          "when"             "efficac1"         "efficac2"         "efficac3"         "efficac4"         "member"           "pid"              "strength"         "strengta"         "sympsoc"          "symplab"          "symplib"          "sympchr"          "sympc"            "sympcons"         "sympprog"         "sympsocl"         "symplabl"         "symplibl"         "sympchrl"         "sympcl"           "sympconl"         "sympprol"         "LRR"              "lrsoc"            "lrlab"            "lrlib"            "lrchr"            "lrc"             
##  [53] "lrcons"           "lrprog"           "econom1"          "econom2"          "EeconS"           "unemploy"         "blame1"           "blame1a"          "blame2"           "blame2a"          "hv20"             "sol20"            "miljo20"          "moral20"          "mpm"              "opind1"           "opind2"           "opind3"           "opind4"           "opind5"           "opind6"           "opind7"           "opind8"           "opind9"           "opind10"          "opind11"          "opind12"          "opind13"          "opind14"          "soli1"            "soli2"            "soli3"            "soli4"            "soli5"            "soli6"            "soli7"            "soli8"            "soli9"            "soli10"           "soli11"           "soli12"           "soli13"           "soli14"           "vern1"            "vern2"            "vern3"            "vern4"            "vern5"            "vern6"            "vern7"            "vern8"            "vern9"           
## [105] "vern10"           "vern11"           "vern12"           "vern13"           "moral1"           "moral2"           "moral3"           "moral4"           "moral5"           "moral6"           "moral7"           "moral8"           "moral9"           "moral10"          "moral11"          "moral12"          "moral13"          "moral14"          "nato"             "eu"               "aid"              "imp1"             "imp2"             "Vt"               "choice"           "recall"           "Va"               "NP"               "Pl.1"             "Pl.2"             "Pl.3"             "Pl.4"             "Pl.5"             "Pl.6"             "Ll.1"             "Ll.2"             "Ll.3"             "Ll.4"             "Ll.5"             "Ll.6"             "LRP.1"            "LRP.2"            "LRP.3"            "LRP.4"            "LRP.5"            "LRP.6"            "LR"               "Eecon"            "P1P2rat"          "GDM"              "PartyFamilyCode2" "PartyFamilyCode3"
## [157] "PartyFamilyCode5" "PartyFamilyCode6" "PartyFamilyCode8" "PartyFamilyCode9" "Pf.1"             "Pf.2"             "Pf.3"             "Pf.4"             "Pf.5"             "Pf.6"             "CoalCode"         "CMPid.1"          "CMPid.2"          "CMPid.3"          "CMPid.4"          "CMPid.5"          "CMPid.6"          "PrePost"          "Pi"
```

``` r
de5=de5[,c(1,2,3,132,128,131,133:144,151,47,145:150,152,57,153,154,161:174,7,175)]
colnames(de5)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
de5[colnames(de5)]=sapply(de5[colnames(de5)],as.numeric)


#SWEDEN EV de6:----
de6=read_dta("ZA3911_se_1956-1998.dta")
colnames(de6)
```

```
##   [1] "id"       "year"     "country"  "sex"      "age3"     "age7"     "edu"      "party"    "urban"    "ownhouse" "work"     "union"    "church"   "polintr"  "disc"     "when"     "pis"      "vote"     "married"  "s4"       "s5"       "age"      "subclass" "incomeo"  "incomeh"  "disc1"    "disc2"    "disc3"    "partyr"   "issc15"   "issc16"   "issc17"   "issc19"   "issc20"   "issc21"   "issc22"   "s3"       "issc11"   "issc2"    "issc1"    "issc12"   "issc10"   "issc13"   "issc14"   "issd7"    "issd11"   "laen"     "lrpown"   "mediapol" "pid"      "voter"    "issc3"    "issc5"    "issc9"    "iss405"   "iss412"   "iss413"   "iss407"   "iss408"   "iss409"   "iss410"   "iss411"   "weight70" "iss418"   "disc5"    "econ11"   "issd1"    "issd3"    "issd2"    "iss414"   "weight76" "egpclass" "sektor"   "bypost"   "econ21"   "econ22"   "iss141b"  "iss242"   "iss121"   "iss183"   "iss143"   "iss124"   "iss125"   "iss221"   "iss222"   "iss144"   "iss161"   "iss184"   "iss191"   "iss415"  
##  [91] "mediaexp" "disc10"   "member1"  "symp1"    "symp2"    "symp3"    "symp4"    "symp5"    "sympl1"   "sympl2"   "sympl3"   "sympl4"   "sympl5"   "lrp1"     "lrp2"     "lrp3"     "lrp4"     "lrp5"     "iss141"   "iss182"   "iss220"   "iss185"   "iss240"   "iss169"   "issue17a" "issue18a" "subcl2"   "partic13" "symp6"    "symp7"    "lrp6"     "lrp7"     "econ12"   "iss100"   "iss102"   "iss160"   "iss223"   "issb1"    "issb2"    "issb3"    "issb7"    "issb8"    "issb9"    "imp1"     "imp2"     "imp4"     "imp15"    "evv1"     "evv2"     "evv4"     "evv15"    "evs1"     "evs2"     "evs4"     "evs15"    "evc1"     "evc2"     "evc4"     "evc15"    "evfp1"    "evfp2"    "evfp4"    "evfp15"   "evm1"     "evm2"     "evm4"     "evm15"    "sympl6"   "iss145"   "iss147"   "iss181b"  "inglhpm"  "imp3"     "imp6"     "imp7"     "imp14"    "evv3"     "evv6"     "evv14"    "evs3"     "evs6"     "evs7"     "evs14"    "evc3"     "evc6"     "evc7"     "evc14"    "evfp3"    "evfp6"    "evfp7"   
## [181] "evfp14"   "evm3"     "evm6"     "evm7"     "evm14"    "iss241"   "iss140"   "iss120"   "iss164"   "iss419"   "imp5"     "evv5"     "evs5"     "evc5"     "evfp5"    "evm5"     "evkd1"    "evkd2"    "evkd3"    "evkd4"    "evkd5"    "evkd6"    "evkd7"    "evkd14"   "evmp1"    "evmp2"    "evmp3"    "evmp4"    "evmp5"    "evmp6"    "evmp7"    "evmp14"   "subcl3"   "symp8"    "sympl7"   "sympl8a"  "sympl8b"  "lrp8"     "issb10"   "issb4"    "issb12"   "issb13"   "imp9"     "imp10"    "imp11"    "evv91"    "evv10"    "evv11"    "evs91"    "evs10"    "evs11"    "evc91"    "evc10"    "evc11"    "evfp91"   "evfp10"   "evfp11"   "evm91"    "evm10"    "evm11"    "evkd91"   "evkd10"   "evkd11"   "evmp91"   "evmp10"   "evmp11"   "evnyd1"   "evnyd2"   "evnyd3"   "evnyd4"   "evnyd5"   "evnyd6"   "evnyd7"   "evnyd91"  "evnyd14"  "evnyd10"  "evnyd11"  "iss123"   "issb14"   "imp8"     "imp12"    "imp13"    "evv12"    "evv13"    "evs12"    "evs13"    "evc12"    "evc13"    "evfp12"   "evfp13"  
## [271] "evm12"    "evm13"    "evkd12"   "evkd13"   "evmp12"   "evmp13"   "evnyd12"  "evnyd13"  "iss122"   "iss162"   "iss181"   "iss163"   "issb15"   "evv8"     "evv92"    "evs8"     "evs92"    "evc8"     "evc92"    "evfp8"    "evfp92"   "evm8"     "evm92"    "evkd8"    "evkd92"   "evmp8"    "evmp92"   "incomeo5" "incomeh5" "issue19a" "evkd15"   "evmp15"   "evnyd8"   "evnyd92"  "evnyd15"  "iss420"
```

``` r
colnames(de6)[colnames(de6)=="year"]="Ey"#Election Year
de6$Ey=as.numeric(de6$Ey)
de6=de6[de6$Ey>=1982,]#get rid of elections without likability
colnames(de6)[colnames(de6)=="country"]="Ec"#Election Country
de6$Ec=6
de6$Ec=as.numeric(de6$Ec)
colnames(de6)[colnames(de6)=="age"]="Rage"#Respondent Age
de6$Rage=as.numeric(de6$Rage)
de6$Rage[de6$Rage>100]=NA
#Vt#Vote Turnout (0 did not vote; 1 voted)
colnames(de6)[colnames(de6)=="vote"]="Vt"
de6$Vt[de6$Vt>2]=NA
table(de6$Vt)
```

```
## 
##     0     1 
##  1368 15089
```

``` r
#"Va"#Vote Alphabetical (here numbers), by vote share:
de6$Va=NA
de6$Va[de6$Ey==1982&de6$party==2]=1#1982:2,5,3,4,1
de6$Va[de6$Ey==1982&de6$party==5]=2
de6$Va[de6$Ey==1982&de6$party==3]=3
de6$Va[de6$Ey==1982&de6$party==4]=4
de6$Va[de6$Ey==1982&de6$party==1]=5
de6$Va[de6$Ey==1985&de6$party==2]=1#1985:2,5,4,3,1,10
de6$Va[de6$Ey==1985&de6$party==5]=2
de6$Va[de6$Ey==1985&de6$party==4]=3
de6$Va[de6$Ey==1985&de6$party==3]=4
de6$Va[de6$Ey==1985&de6$party==1]=5
de6$Va[de6$Ey==1985&de6$party==10]=6
de6$Va[de6$Ey==1988&de6$party==2]=1#1988:2,5,4,3,1
de6$Va[de6$Ey==1988&de6$party==5]=2
de6$Va[de6$Ey==1988&de6$party==4]=3
de6$Va[de6$Ey==1988&de6$party==3]=4
de6$Va[de6$Ey==1988&de6$party==1]=5
de6$Va[de6$Ey==1991&de6$party==2]=1#1991:2,5,4,3,10,12
de6$Va[de6$Ey==1991&de6$party==5]=2
de6$Va[de6$Ey==1991&de6$party==4]=3
de6$Va[de6$Ey==1991&de6$party==3]=4
de6$Va[de6$Ey==1991&de6$party==10]=5
de6$Va[de6$Ey==1991&de6$party==12]=6
de6$Va[de6$Ey==1994&de6$party==2]=1#1994:2,5,3,4,1,11
de6$Va[de6$Ey==1994&de6$party==5]=2
de6$Va[de6$Ey==1994&de6$party==3]=3
de6$Va[de6$Ey==1994&de6$party==4]=4
de6$Va[de6$Ey==1994&de6$party==1]=5
de6$Va[de6$Ey==1994&de6$party==11]=6
de6$Va[de6$Ey==1998&de6$party==2]=1#1998:2,5,1,10,3,4
de6$Va[de6$Ey==1998&de6$party==5]=2
de6$Va[de6$Ey==1998&de6$party==1]=3
de6$Va[de6$Ey==1998&de6$party==10]=4
de6$Va[de6$Ey==1998&de6$party==3]=5
de6$Va[de6$Ey==1998&de6$party==4]=6
de6$Rwd=1#Respondent Weight Demographic (there's no weight, all entries set to 1)
#Number of Parties:
de6$NP=NA
de6$NP[de6$Ey==1982]=5
de6$NP[de6$Ey==1985]=6
de6$NP[de6$Ey==1988]=5
de6$NP[de6$Ey==1991]=6
de6$NP[de6$Ey==1994]=6
de6$NP[de6$Ey==1998]=6
#party likability:
de6$Pl.1=NA
de6$Pl.2=NA
de6$Pl.3=NA
de6$Pl.4=NA
de6$Pl.5=NA
de6$Pl.6=NA
# de6$Pl.7=NA
table(de6$symp2[de6$Ey==1998])
```

```
## 
##                -5                -4    -3.39990234375                -3    -2.39990234375                -2    -1.39990234375                -1 -0.39996337890625                 0   0.5999755859375                 1    1.599853515625                 2       2.599609375                 3       3.599609375                 4       4.599609375                 5                 8                 9                99 
##                88                24                32                51                62                51               130                56                90               108               195                98               117               108               136               155               168               121               105               162                 6                 2               296
```

``` r
de6$Pl.1[de6$Ey==1982]=de6$symp2[de6$Ey==1982]#1982:2,5,3,4,1
de6$Pl.2[de6$Ey==1982]=de6$symp5[de6$Ey==1982]
de6$Pl.3[de6$Ey==1982]=de6$symp3[de6$Ey==1982]
de6$Pl.4[de6$Ey==1982]=de6$symp4[de6$Ey==1982]
de6$Pl.5[de6$Ey==1982]=de6$symp1[de6$Ey==1982]
de6$Pl.1[de6$Ey==1985]=de6$symp2[de6$Ey==1985]#1985:2,5,4,3,1,10
de6$Pl.2[de6$Ey==1985]=de6$symp5[de6$Ey==1985]
de6$Pl.3[de6$Ey==1985]=de6$symp4[de6$Ey==1985]
de6$Pl.4[de6$Ey==1985]=de6$symp3[de6$Ey==1985]
de6$Pl.5[de6$Ey==1985]=de6$symp1[de6$Ey==1985]
de6$Pl.6[de6$Ey==1985]=de6$symp6[de6$Ey==1985]
de6$Pl.1[de6$Ey==1988]=de6$symp2[de6$Ey==1988]#1988:2,5,4,3,1
de6$Pl.2[de6$Ey==1988]=de6$symp5[de6$Ey==1988]
de6$Pl.3[de6$Ey==1988]=de6$symp4[de6$Ey==1988]
de6$Pl.4[de6$Ey==1988]=de6$symp3[de6$Ey==1988]
de6$Pl.5[de6$Ey==1988]=de6$symp1[de6$Ey==1988]
de6$Pl.1[de6$Ey==1991]=de6$symp2[de6$Ey==1991]#1991:2,5,4,3,10,12
de6$Pl.2[de6$Ey==1991]=de6$symp5[de6$Ey==1991]
de6$Pl.3[de6$Ey==1991]=de6$symp4[de6$Ey==1991]
de6$Pl.4[de6$Ey==1991]=de6$symp3[de6$Ey==1991]
de6$Pl.5[de6$Ey==1991]=de6$symp6[de6$Ey==1991]
de6$Pl.6[de6$Ey==1991]=de6$symp8[de6$Ey==1991]
de6$Pl.1[de6$Ey==1994]=de6$symp2[de6$Ey==1994]#1994:2,5,3,4,1,11
de6$Pl.2[de6$Ey==1994]=de6$symp5[de6$Ey==1994]
de6$Pl.3[de6$Ey==1994]=de6$symp3[de6$Ey==1994]
de6$Pl.4[de6$Ey==1994]=de6$symp4[de6$Ey==1994]
de6$Pl.5[de6$Ey==1994]=de6$symp1[de6$Ey==1994]
de6$Pl.6[de6$Ey==1994]=de6$symp7[de6$Ey==1994]
de6$Pl.1[de6$Ey==1998]=de6$symp2[de6$Ey==1998]#1998:2,5,1,10,3,4
de6$Pl.2[de6$Ey==1998]=de6$symp5[de6$Ey==1998]
de6$Pl.3[de6$Ey==1998]=de6$symp1[de6$Ey==1998]
de6$Pl.4[de6$Ey==1998]=de6$symp6[de6$Ey==1998]
de6$Pl.5[de6$Ey==1998]=de6$symp3[de6$Ey==1998]
de6$Pl.6[de6$Ey==1998]=de6$symp4[de6$Ey==1998]
de6$Pl.1[de6$Pl.1>5]=NA#recoding to 0-10 scale
de6$Pl.2[de6$Pl.2>5]=NA
de6$Pl.3[de6$Pl.3>5]=NA
de6$Pl.4[de6$Pl.4>5]=NA
de6$Pl.5[de6$Pl.5>5]=NA
de6$Pl.6[de6$Pl.6>5]=NA
de6$Pl.1=de6$Pl.1+5
de6$Pl.2=de6$Pl.2+5
de6$Pl.3=de6$Pl.3+5
de6$Pl.4=de6$Pl.4+5
de6$Pl.5=de6$Pl.5+5
de6$Pl.6=de6$Pl.6+5
#leader likability:
de6$Ll.1=NA
de6$Ll.2=NA
de6$Ll.3=NA
de6$Ll.4=NA
de6$Ll.5=NA
de6$Ll.6=NA
# de6$Ll.7=NA
de6$Ll.1[de6$Ey==1982]=de6$sympl2[de6$Ey==1982]#1982:2,5,3,4,1
de6$Ll.2[de6$Ey==1982]=de6$sympl5[de6$Ey==1982]
de6$Ll.3[de6$Ey==1982]=de6$sympl3[de6$Ey==1982]
de6$Ll.4[de6$Ey==1982]=de6$sympl4[de6$Ey==1982]
de6$Ll.5[de6$Ey==1982]=de6$sympl1[de6$Ey==1982]
de6$Ll.1[de6$Ey==1985]=de6$sympl2[de6$Ey==1985]#1985:2,5,4,3,1,10
de6$Ll.2[de6$Ey==1985]=de6$sympl5[de6$Ey==1985]
de6$Ll.3[de6$Ey==1985]=de6$sympl4[de6$Ey==1985]
de6$Ll.4[de6$Ey==1985]=de6$sympl3[de6$Ey==1985]
de6$Ll.5[de6$Ey==1985]=de6$sympl1[de6$Ey==1985]
de6$Ll.6[de6$Ey==1985]=de6$sympl6[de6$Ey==1985]
de6$Ll.1[de6$Ey==1988]=de6$sympl2[de6$Ey==1988]#1988:2,5,4,3,1
de6$Ll.2[de6$Ey==1988]=de6$sympl5[de6$Ey==1988]
de6$Ll.3[de6$Ey==1988]=de6$sympl4[de6$Ey==1988]
de6$Ll.4[de6$Ey==1988]=de6$sympl3[de6$Ey==1988]
de6$Ll.5[de6$Ey==1988]=de6$sympl1[de6$Ey==1988]
de6$Ll.1[de6$Ey==1991]=de6$sympl2[de6$Ey==1991]#1991:2,5,4,3,10,12
de6$Ll.2[de6$Ey==1991]=de6$sympl5[de6$Ey==1991]
de6$Ll.3[de6$Ey==1991]=de6$sympl4[de6$Ey==1991]
de6$Ll.4[de6$Ey==1991]=de6$sympl3[de6$Ey==1991]
de6$Ll.5[de6$Ey==1991]=de6$sympl6[de6$Ey==1991]
de6$Ll.6[de6$Ey==1991]=de6$sympl8a[de6$Ey==1991]
de6$Ll.1[de6$Ey==1994]=de6$sympl2[de6$Ey==1994]#1994:2,5,3,4,1,11
de6$Ll.2[de6$Ey==1994]=de6$sympl5[de6$Ey==1994]
de6$Ll.3[de6$Ey==1994]=de6$sympl3[de6$Ey==1994]
de6$Ll.4[de6$Ey==1994]=de6$sympl4[de6$Ey==1994]
de6$Ll.5[de6$Ey==1994]=de6$sympl1[de6$Ey==1994]
de6$Ll.6[de6$Ey==1994]=de6$sympl7[de6$Ey==1994]
de6$Ll.1[de6$Ey==1998]=de6$sympl2[de6$Ey==1998]#1998:2,5,1,10,3,4
de6$Ll.2[de6$Ey==1998]=de6$sympl5[de6$Ey==1998]
de6$Ll.3[de6$Ey==1998]=de6$sympl1[de6$Ey==1998]
de6$Ll.4[de6$Ey==1998]=de6$sympl6[de6$Ey==1998]
de6$Ll.5[de6$Ey==1998]=de6$sympl3[de6$Ey==1998]
de6$Ll.6[de6$Ey==1998]=de6$sympl4[de6$Ey==1998]
de6$Ll.1[de6$Ll.1>5]=NA#recoding to 0-10 scale
de6$Ll.2[de6$Ll.2>5]=NA
de6$Ll.3[de6$Ll.3>5]=NA
de6$Ll.4[de6$Ll.4>5]=NA
de6$Ll.5[de6$Ll.5>5]=NA
de6$Ll.6[de6$Ll.6>5]=NA
de6$Ll.1=de6$Ll.1+5
de6$Ll.2=de6$Ll.2+5
de6$Ll.3=de6$Ll.3+5
de6$Ll.4=de6$Ll.4+5
de6$Ll.5=de6$Ll.5+5
de6$Ll.6=de6$Ll.6+5
#LRR=Left Right Respondent (voter LR self):
colnames(de6)[colnames(de6)=="lrpown"]="LRR"
de6$LRR[de6$LRR>10]=NA#recoding to 0-10 scale
de6$LRR=as.numeric(de6$LRR)
#LRP.i=Left Right Parties:
de6$LRP.1=NA
de6$LRP.2=NA
de6$LRP.3=NA
de6$LRP.4=NA
de6$LRP.5=NA
de6$LRP.6=NA
# de6$LRP.7=NA
de6$LRP.1[de6$Ey==1982]=de6$lrp2[de6$Ey==1982]#1982:2,5,3,4,1
de6$LRP.2[de6$Ey==1982]=de6$lrp5[de6$Ey==1982]
de6$LRP.3[de6$Ey==1982]=de6$lrp3[de6$Ey==1982]
de6$LRP.4[de6$Ey==1982]=de6$lrp4[de6$Ey==1982]
de6$LRP.5[de6$Ey==1982]=de6$lrp1[de6$Ey==1982]
de6$LRP.1[de6$Ey==1985]=de6$lrp2[de6$Ey==1985]#1985:2,5,4,3,1,10
de6$LRP.2[de6$Ey==1985]=de6$lrp5[de6$Ey==1985]
de6$LRP.3[de6$Ey==1985]=de6$lrp4[de6$Ey==1985]
de6$LRP.4[de6$Ey==1985]=de6$lrp3[de6$Ey==1985]
de6$LRP.5[de6$Ey==1985]=de6$lrp1[de6$Ey==1985]
de6$LRP.6[de6$Ey==1985]=de6$lrp6[de6$Ey==1985]
de6$LRP.1[de6$Ey==1988]=de6$lrp2[de6$Ey==1988]#1988:2,5,4,3,1
de6$LRP.2[de6$Ey==1988]=de6$lrp5[de6$Ey==1988]
de6$LRP.3[de6$Ey==1988]=de6$lrp4[de6$Ey==1988]
de6$LRP.4[de6$Ey==1988]=de6$lrp3[de6$Ey==1988]
de6$LRP.5[de6$Ey==1988]=de6$lrp1[de6$Ey==1988]
de6$LRP.1[de6$Ey==1991]=de6$lrp2[de6$Ey==1991]#1991:2,5,4,3,10,12
de6$LRP.2[de6$Ey==1991]=de6$lrp5[de6$Ey==1991]
de6$LRP.3[de6$Ey==1991]=de6$lrp4[de6$Ey==1991]
de6$LRP.4[de6$Ey==1991]=de6$lrp3[de6$Ey==1991]
de6$LRP.5[de6$Ey==1991]=de6$lrp6[de6$Ey==1991]
de6$LRP.6[de6$Ey==1991]=de6$lrp8[de6$Ey==1991]
de6$LRP.1[de6$Ey==1994]=de6$lrp2[de6$Ey==1994]#1994:2,5,3,4,1,11
de6$LRP.2[de6$Ey==1994]=de6$lrp5[de6$Ey==1994]
de6$LRP.3[de6$Ey==1994]=de6$lrp3[de6$Ey==1994]
de6$LRP.4[de6$Ey==1994]=de6$lrp4[de6$Ey==1994]
de6$LRP.5[de6$Ey==1994]=de6$lrp1[de6$Ey==1994]
de6$LRP.6[de6$Ey==1994]=de6$lrp7[de6$Ey==1994]
de6$LRP.1[de6$Ey==1998]=de6$lrp2[de6$Ey==1998]#1998:2,5,1,10,3,4
de6$LRP.2[de6$Ey==1998]=de6$lrp5[de6$Ey==1998]
de6$LRP.3[de6$Ey==1998]=de6$lrp1[de6$Ey==1998]
de6$LRP.4[de6$Ey==1998]=de6$lrp6[de6$Ey==1998]
de6$LRP.5[de6$Ey==1998]=de6$lrp3[de6$Ey==1998]
de6$LRP.6[de6$Ey==1998]=de6$lrp4[de6$Ey==1998]
de6$LRP.1[de6$LRP.1>10]=NA#recoding to 0-10 scale
de6$LRP.2[de6$LRP.2>10]=NA
de6$LRP.3[de6$LRP.3>10]=NA
de6$LRP.4[de6$LRP.4>10]=NA
de6$LRP.5[de6$LRP.5>10]=NA
de6$LRP.6[de6$LRP.6>10]=NA
#Elections with LRR and LRP:
de6$LR=NA
de6$LR[de6$Ey==1982]=1
de6$LR[de6$Ey==1985]=1
de6$LR[de6$Ey==1988]=1
de6$LR[de6$Ey==1991]=1
de6$LR[de6$Ey==1994]=1
de6$LR[de6$Ey==1998]=1
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
# 1. MUCH BETTER                 
# 3. STAYED THE SAME              
# 5. MUCH WORSE
colnames(de6)[colnames(de6)=="econ12"]="EeconS"
de6$EeconS[de6$EeconS>5]=NA
de6$EeconS[de6$Ey==1982]=NA#scale in the data different than scale in the codebook
#recode EeconS from EV scale
# 1. GOTTEN BETTER c(1,2,3,4,5)
# 5. GOTTEN WORSE 
# to TEV scale, noting that the TEV used the conversion scale below for same elections:
# 0. Negative evaluation c(0, 0.25, 0.5, 0.75, 1)
# 1. Positive evaluation
de6$EeconS[de6$EeconS==1]=1
de6$EeconS[de6$EeconS==2]=0.75
de6$EeconS[de6$EeconS==3]=0.5
de6$EeconS[de6$EeconS==4]=0.25
de6$EeconS[de6$EeconS==5]=0
#Elections with EeconS:
de6$Eecon=NA
de6$Eecon[de6$Ey==1982]=0
de6$Eecon[de6$Ey==1985]=1
de6$Eecon[de6$Ey==1988]=1
de6$Eecon[de6$Ey==1991]=1
de6$Eecon[de6$Ey==1994]=1
de6$Eecon[de6$Ey==1998]=1
#Seats to vote ratios:
de6$P1P2rat=NA
de6$P1P2rat[de6$Ey==1982]=1.00
de6$P1P2rat[de6$Ey==1985]=1.00
de6$P1P2rat[de6$Ey==1988]=1.00
de6$P1P2rat[de6$Ey==1991]=1.00
de6$P1P2rat[de6$Ey==1994]=1.00
de6$P1P2rat[de6$Ey==1998]=1.01
#Gallagher Disproportionality measure:
de6$GDM=NA
de6$GDM[de6$Ey==1982]=2.40
de6$GDM[de6$Ey==1985]=1.35
de6$GDM[de6$Ey==1988]=2.45
de6$GDM[de6$Ey==1991]=2.86
de6$GDM[de6$Ey==1994]=1.18
de6$GDM[de6$Ey==1998]=0.97
#Party family:
de6$PartyFamilyCode1=20
de6$PartyFamilyCode2=30
de6$PartyFamilyCode3=80
de6$PartyFamilyCode4=40
de6$PartyFamilyCode5=60
de6$PartyFamilyCode6=50
de6$PartyFamilyCode7=10
de6$PartyFamilyCode8=95
# 1 Left Party (Vänsterpartiet)
# 2 Social Democrats (Socialdemokraterna)
# 3 Center Party (Centerpartiet)
# 4 People’s Party Liberals (Folkpartiet Liberalerna)
# 5 Moderate Party (Moderata Samlingspartiet)
# 10 (6) Christian Democrats (Kristdemokraterna)
# 11 (7) Green Party (Miljöpartiet de Gröna)
# 12 (8) New Democracy (Ny Demokrati)
de6$Pf.1=NA
de6$Pf.2=NA
de6$Pf.3=NA
de6$Pf.4=NA
de6$Pf.5=NA
de6$Pf.6=NA
# de6$Pf.7=NA
de6$Pf.1[de6$Ey==1982]=de6$PartyFamilyCode2[de6$Ey==1982]#1982:2,5,3,4,1
de6$Pf.2[de6$Ey==1982]=de6$PartyFamilyCode5[de6$Ey==1982]
de6$Pf.3[de6$Ey==1982]=de6$PartyFamilyCode3[de6$Ey==1982]
de6$Pf.4[de6$Ey==1982]=de6$PartyFamilyCode4[de6$Ey==1982]
de6$Pf.5[de6$Ey==1982]=de6$PartyFamilyCode1[de6$Ey==1982]
de6$Pf.1[de6$Ey==1985]=de6$PartyFamilyCode2[de6$Ey==1985]#1985:2,5,4,3,1,10
de6$Pf.2[de6$Ey==1985]=de6$PartyFamilyCode5[de6$Ey==1985]
de6$Pf.3[de6$Ey==1985]=de6$PartyFamilyCode4[de6$Ey==1985]
de6$Pf.4[de6$Ey==1985]=de6$PartyFamilyCode3[de6$Ey==1985]
de6$Pf.5[de6$Ey==1985]=de6$PartyFamilyCode1[de6$Ey==1985]
de6$Pf.6[de6$Ey==1985]=de6$PartyFamilyCode6[de6$Ey==1985]
de6$Pf.1[de6$Ey==1988]=de6$PartyFamilyCode2[de6$Ey==1988]#1988:2,5,4,3,1
de6$Pf.2[de6$Ey==1988]=de6$PartyFamilyCode5[de6$Ey==1988]
de6$Pf.3[de6$Ey==1988]=de6$PartyFamilyCode4[de6$Ey==1988]
de6$Pf.4[de6$Ey==1988]=de6$PartyFamilyCode3[de6$Ey==1988]
de6$Pf.5[de6$Ey==1988]=de6$PartyFamilyCode1[de6$Ey==1988]
de6$Pf.1[de6$Ey==1991]=de6$PartyFamilyCode2[de6$Ey==1991]#1991:2,5,4,3,10,12
de6$Pf.2[de6$Ey==1991]=de6$PartyFamilyCode5[de6$Ey==1991]
de6$Pf.3[de6$Ey==1991]=de6$PartyFamilyCode4[de6$Ey==1991]
de6$Pf.4[de6$Ey==1991]=de6$PartyFamilyCode3[de6$Ey==1991]
de6$Pf.5[de6$Ey==1991]=de6$PartyFamilyCode6[de6$Ey==1991]
de6$Pf.6[de6$Ey==1991]=de6$PartyFamilyCode8[de6$Ey==1991]
de6$Pf.1[de6$Ey==1994]=de6$PartyFamilyCode2[de6$Ey==1994]#1994:2,5,3,4,1,11
de6$Pf.2[de6$Ey==1994]=de6$PartyFamilyCode5[de6$Ey==1994]
de6$Pf.3[de6$Ey==1994]=de6$PartyFamilyCode3[de6$Ey==1994]
de6$Pf.4[de6$Ey==1994]=de6$PartyFamilyCode4[de6$Ey==1994]
de6$Pf.5[de6$Ey==1994]=de6$PartyFamilyCode1[de6$Ey==1994]
de6$Pf.6[de6$Ey==1994]=de6$PartyFamilyCode7[de6$Ey==1994]
de6$Pf.1[de6$Ey==1998]=de6$PartyFamilyCode2[de6$Ey==1998]#1998:2,5,1,10,3,4
de6$Pf.2[de6$Ey==1998]=de6$PartyFamilyCode5[de6$Ey==1998]
de6$Pf.3[de6$Ey==1998]=de6$PartyFamilyCode1[de6$Ey==1998]
de6$Pf.4[de6$Ey==1998]=de6$PartyFamilyCode6[de6$Ey==1998]
de6$Pf.5[de6$Ey==1998]=de6$PartyFamilyCode3[de6$Ey==1998]
de6$Pf.6[de6$Ey==1998]=de6$PartyFamilyCode4[de6$Ey==1998]
#coding coalition status:
de6$CoalCode=0
#CMPid.i:
de6$CMPid.1=NA#create CMPid:
de6$CMPid.2=NA
de6$CMPid.3=NA
de6$CMPid.4=NA
de6$CMPid.5=NA
de6$CMPid.6=NA
de6$CMPid.1=as.numeric(de6$CMPid.1)#recode as numeric:
de6$CMPid.2=as.numeric(de6$CMPid.2)
de6$CMPid.3=as.numeric(de6$CMPid.3)
de6$CMPid.4=as.numeric(de6$CMPid.4)
de6$CMPid.5=as.numeric(de6$CMPid.5)
de6$CMPid.6=as.numeric(de6$CMPid.6)
#PrePost:
de6$PrePost=as.numeric(NA)
#"Pi"#Party identification:
de6$Pi=NA
de6$Pi[de6$Ey==1982&de6$pid==2]=1#1982:2,5,3,4,1
de6$Pi[de6$Ey==1982&de6$pid==5]=2
de6$Pi[de6$Ey==1982&de6$pid==3]=3
de6$Pi[de6$Ey==1982&de6$pid==4]=4
de6$Pi[de6$Ey==1982&de6$pid==1]=5
de6$Pi[de6$Ey==1985&de6$pid==2]=1#1985:2,5,4,3,1,10
de6$Pi[de6$Ey==1985&de6$pid==5]=2
de6$Pi[de6$Ey==1985&de6$pid==4]=3
de6$Pi[de6$Ey==1985&de6$pid==3]=4
de6$Pi[de6$Ey==1985&de6$pid==1]=5
de6$Pi[de6$Ey==1985&de6$pid==10]=6
de6$Pi[de6$Ey==1988&de6$pid==2]=1#1988:2,5,4,3,1
de6$Pi[de6$Ey==1988&de6$pid==5]=2
de6$Pi[de6$Ey==1988&de6$pid==4]=3
de6$Pi[de6$Ey==1988&de6$pid==3]=4
de6$Pi[de6$Ey==1988&de6$pid==1]=5
de6$Pi[de6$Ey==1991&de6$pid==2]=1#1991:2,5,4,3,10,12
de6$Pi[de6$Ey==1991&de6$pid==5]=2
de6$Pi[de6$Ey==1991&de6$pid==4]=3
de6$Pi[de6$Ey==1991&de6$pid==3]=4
de6$Pi[de6$Ey==1991&de6$pid==10]=5
de6$Pi[de6$Ey==1991&de6$pid==12]=6
de6$Pi[de6$Ey==1994&de6$pid==2]=1#1994:2,5,3,4,1,11
de6$Pi[de6$Ey==1994&de6$pid==5]=2
de6$Pi[de6$Ey==1994&de6$pid==3]=3
de6$Pi[de6$Ey==1994&de6$pid==4]=4
de6$Pi[de6$Ey==1994&de6$pid==1]=5
de6$Pi[de6$Ey==1994&de6$pid==11]=6
de6$Pi[de6$Ey==1998&de6$pid==2]=1#1998:2,5,1,10,3,4
de6$Pi[de6$Ey==1998&de6$pid==5]=2
de6$Pi[de6$Ey==1998&de6$pid==1]=3
de6$Pi[de6$Ey==1998&de6$pid==10]=4
de6$Pi[de6$Ey==1998&de6$pid==3]=5
de6$Pi[de6$Ey==1998&de6$pid==4]=6
#subset:
colnames(de6)
```

```
##   [1] "id"               "Ey"               "Ec"               "sex"              "age3"             "age7"             "edu"              "party"            "urban"            "ownhouse"         "work"             "union"            "church"           "polintr"          "disc"             "when"             "pis"              "Vt"               "married"          "s4"               "s5"               "Rage"             "subclass"         "incomeo"          "incomeh"          "disc1"            "disc2"            "disc3"            "partyr"           "issc15"           "issc16"           "issc17"           "issc19"           "issc20"           "issc21"           "issc22"           "s3"               "issc11"           "issc2"            "issc1"            "issc12"           "issc10"           "issc13"           "issc14"           "issd7"            "issd11"           "laen"             "LRR"              "mediapol"         "pid"              "voter"            "issc3"           
##  [53] "issc5"            "issc9"            "iss405"           "iss412"           "iss413"           "iss407"           "iss408"           "iss409"           "iss410"           "iss411"           "weight70"         "iss418"           "disc5"            "econ11"           "issd1"            "issd3"            "issd2"            "iss414"           "weight76"         "egpclass"         "sektor"           "bypost"           "econ21"           "econ22"           "iss141b"          "iss242"           "iss121"           "iss183"           "iss143"           "iss124"           "iss125"           "iss221"           "iss222"           "iss144"           "iss161"           "iss184"           "iss191"           "iss415"           "mediaexp"         "disc10"           "member1"          "symp1"            "symp2"            "symp3"            "symp4"            "symp5"            "sympl1"           "sympl2"           "sympl3"           "sympl4"           "sympl5"           "lrp1"            
## [105] "lrp2"             "lrp3"             "lrp4"             "lrp5"             "iss141"           "iss182"           "iss220"           "iss185"           "iss240"           "iss169"           "issue17a"         "issue18a"         "subcl2"           "partic13"         "symp6"            "symp7"            "lrp6"             "lrp7"             "EeconS"           "iss100"           "iss102"           "iss160"           "iss223"           "issb1"            "issb2"            "issb3"            "issb7"            "issb8"            "issb9"            "imp1"             "imp2"             "imp4"             "imp15"            "evv1"             "evv2"             "evv4"             "evv15"            "evs1"             "evs2"             "evs4"             "evs15"            "evc1"             "evc2"             "evc4"             "evc15"            "evfp1"            "evfp2"            "evfp4"            "evfp15"           "evm1"             "evm2"             "evm4"            
## [157] "evm15"            "sympl6"           "iss145"           "iss147"           "iss181b"          "inglhpm"          "imp3"             "imp6"             "imp7"             "imp14"            "evv3"             "evv6"             "evv14"            "evs3"             "evs6"             "evs7"             "evs14"            "evc3"             "evc6"             "evc7"             "evc14"            "evfp3"            "evfp6"            "evfp7"            "evfp14"           "evm3"             "evm6"             "evm7"             "evm14"            "iss241"           "iss140"           "iss120"           "iss164"           "iss419"           "imp5"             "evv5"             "evs5"             "evc5"             "evfp5"            "evm5"             "evkd1"            "evkd2"            "evkd3"            "evkd4"            "evkd5"            "evkd6"            "evkd7"            "evkd14"           "evmp1"            "evmp2"            "evmp3"            "evmp4"           
## [209] "evmp5"            "evmp6"            "evmp7"            "evmp14"           "subcl3"           "symp8"            "sympl7"           "sympl8a"          "sympl8b"          "lrp8"             "issb10"           "issb4"            "issb12"           "issb13"           "imp9"             "imp10"            "imp11"            "evv91"            "evv10"            "evv11"            "evs91"            "evs10"            "evs11"            "evc91"            "evc10"            "evc11"            "evfp91"           "evfp10"           "evfp11"           "evm91"            "evm10"            "evm11"            "evkd91"           "evkd10"           "evkd11"           "evmp91"           "evmp10"           "evmp11"           "evnyd1"           "evnyd2"           "evnyd3"           "evnyd4"           "evnyd5"           "evnyd6"           "evnyd7"           "evnyd91"          "evnyd14"          "evnyd10"          "evnyd11"          "iss123"           "issb14"           "imp8"            
## [261] "imp12"            "imp13"            "evv12"            "evv13"            "evs12"            "evs13"            "evc12"            "evc13"            "evfp12"           "evfp13"           "evm12"            "evm13"            "evkd12"           "evkd13"           "evmp12"           "evmp13"           "evnyd12"          "evnyd13"          "iss122"           "iss162"           "iss181"           "iss163"           "issb15"           "evv8"             "evv92"            "evs8"             "evs92"            "evc8"             "evc92"            "evfp8"            "evfp92"           "evm8"             "evm92"            "evkd8"            "evkd92"           "evmp8"            "evmp92"           "incomeo5"         "incomeh5"         "issue19a"         "evkd15"           "evmp15"           "evnyd8"           "evnyd92"          "evnyd15"          "iss420"           "Va"               "Rwd"              "NP"               "Pl.1"             "Pl.2"             "Pl.3"            
## [313] "Pl.4"             "Pl.5"             "Pl.6"             "Ll.1"             "Ll.2"             "Ll.3"             "Ll.4"             "Ll.5"             "Ll.6"             "LRP.1"            "LRP.2"            "LRP.3"            "LRP.4"            "LRP.5"            "LRP.6"            "LR"               "Eecon"            "P1P2rat"          "GDM"              "PartyFamilyCode1" "PartyFamilyCode2" "PartyFamilyCode3" "PartyFamilyCode4" "PartyFamilyCode5" "PartyFamilyCode6" "PartyFamilyCode7" "PartyFamilyCode8" "Pf.1"             "Pf.2"             "Pf.3"             "Pf.4"             "Pf.5"             "Pf.6"             "CoalCode"         "CMPid.1"          "CMPid.2"          "CMPid.3"          "CMPid.4"          "CMPid.5"          "CMPid.6"          "PrePost"          "Pi"
```

``` r
de6=de6[,c(3,2,308,309,18,307,310:321,328,48,322:327,329,123,330,331,340:353,22,354)]
colnames(de6)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
de6[colnames(de6)]=sapply(de6[colnames(de6)],as.numeric)


#AUSTRALIA LP dl7:----
dl7=dl[dl$Ec==1,]#create country dataset
#first reshape to wide dataset:
dl7$Vn[dl7$Vn==10]=NA#set Vn==NA for NAs
dl7$Rid=paste0(dl7$Ey,dl7$Rid)#create unique Rid
colnames(dl7)
```

```
##  [1] "Ec"      "Ey"      "Rwd"     "Vt"      "Vn"      "Pl"      "Ll"      "LRR"     "LRP"     "PartyID" "Ps"      "Rid"     "Rage"    "Pi"
```

``` r
dl7[c(which(duplicated(dl7[,c(10,12)]))),]#rows with duplicated Rid/PartyID observations
```

```
## # A tibble: 20 × 14
##    Ec               Ey   Rwd Vt           Vn                     Pl        Ll           LRR        LRP        PartyID           Ps Rid       Rage Pi                    
##    <dbl+lbl>     <dbl> <dbl> <dbl+lbl>    <dbl+lbl>              <dbl+lbl> <dbl+lbl>    <dbl+lbl>  <dbl+lbl>  <dbl+lbl>      <dbl> <chr>    <dbl> <dbl+lbl>             
##  1 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         3            3.33       8.89      11 [LP (Aus)]   37.4 1987805     NA 2 [party of 2nd stack]
##  2 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         6            5.56       5.56      11 [LP (Aus)]   37.4 19871442    NA 1 [party of 1st stack]
##  3 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        10 [like]    10 [right] 10 [right] 11 [LP (Aus)]   37.4 19871815    NA 1 [party of 1st stack]
##  4 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         4           NA          5.56      11 [LP (Aus)]   37.4 19872176    NA 2 [party of 2nd stack]
##  5 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA         5            5.56       5.56      11 [LP (Aus)]   37.4 19872263    NA 3 [party of 3rd stack]
##  6 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         7            3.33       5.56      12 [ALP (Aus)]  45.1 1987805     NA 2 [party of 2nd stack]
##  7 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         5            5.56       3.33      12 [ALP (Aus)]  45.1 19871442    NA 1 [party of 1st stack]
##  8 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         0 [dislike] 10 [right]  0 [left]  12 [ALP (Aus)]  45.1 19871815    NA 1 [party of 1st stack]
##  9 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         6           NA          6.67      12 [ALP (Aus)]  45.1 19872176    NA 2 [party of 2nd stack]
## 10 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA         3            5.56       5.56      12 [ALP (Aus)]  45.1 19872263    NA 3 [party of 3rd stack]
## 11 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         0 [dislike]  3.33      10 [right] 13 [NP (Aus)]    8.9 1987805     NA 2 [party of 2nd stack]
## 12 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         5            5.56       4.44      13 [NP (Aus)]    8.9 19871442    NA 1 [party of 1st stack]
## 13 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         0 [dislike] 10 [right] 10 [right] 13 [NP (Aus)]    8.9 19871815    NA 1 [party of 1st stack]
## 14 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         3           NA         NA         13 [NP (Aus)]    8.9 19872176    NA 2 [party of 2nd stack]
## 15 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA         5            5.56       3.33      13 [NP (Aus)]    8.9 19872263    NA 3 [party of 3rd stack]
## 16 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         5            3.33      NA         14 [AD (Aus)]    6.6 1987805     NA 2 [party of 2nd stack]
## 17 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         6            5.56      NA         14 [AD (Aus)]    6.6 19871442    NA 1 [party of 1st stack]
## 18 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         0 [dislike] 10 [right] NA         14 [AD (Aus)]    6.6 19871815    NA 1 [party of 1st stack]
## 19 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         5           NA         NA         14 [AD (Aus)]    6.6 19872176    NA 2 [party of 2nd stack]
## 20 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA         5            5.56      NA         14 [AD (Aus)]    6.6 19872263    NA 3 [party of 3rd stack]
```

``` r
unique(dl7$Rid[duplicated(dl7[,c(10,12)])])#Rid for rows with duplicated Rid/PartyID observations
```

```
## [1] "1987805"  "19871442" "19871815" "19872176" "19872263"
```

``` r
dl7[dl7$Rid==1987805,]
```

```
## # A tibble: 8 × 14
##   Ec               Ey   Rwd Vt           Vn                     Pl        Ll          LRR       LRP        PartyID           Ps Rid      Rage Pi                    
##   <dbl+lbl>     <dbl> <dbl> <dbl+lbl>    <dbl+lbl>              <dbl+lbl> <dbl+lbl>   <dbl+lbl> <dbl+lbl>  <dbl+lbl>      <dbl> <chr>   <dbl> <dbl+lbl>             
## 1 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        3           5.56      NA         11 [LP (Aus)]   37.4 1987805    NA 4 [party of 4th stack]
## 2 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        3           3.33       8.89      11 [LP (Aus)]   37.4 1987805    NA 2 [party of 2nd stack]
## 3 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        8           5.56       7.78      12 [ALP (Aus)]  45.1 1987805    NA 4 [party of 4th stack]
## 4 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        7           3.33       5.56      12 [ALP (Aus)]  45.1 1987805    NA 2 [party of 2nd stack]
## 5 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        0 [dislike] 5.56      NA         13 [NP (Aus)]    8.9 1987805    NA 4 [party of 4th stack]
## 6 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        0 [dislike] 3.33      10 [right] 13 [NP (Aus)]    8.9 1987805    NA 2 [party of 2nd stack]
## 7 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        7           5.56      NA         14 [AD (Aus)]    6.6 1987805    NA 4 [party of 4th stack]
## 8 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        5           3.33      NA         14 [AD (Aus)]    6.6 1987805    NA 2 [party of 2nd stack]
```

``` r
dl7[dl7$Rid==19871442,]
```

```
## # A tibble: 8 × 14
##   Ec               Ey   Rwd Vt           Vn                     Pl        Ll        LRR       LRP       PartyID           Ps Rid       Rage Pi                    
##   <dbl+lbl>     <dbl> <dbl> <dbl+lbl>    <dbl+lbl>              <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl>      <dbl> <chr>    <dbl> <dbl+lbl>             
## 1 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        8         6.67       6.67     11 [LP (Aus)]   37.4 19871442    NA 1 [party of 1st stack]
## 2 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        6         5.56       5.56     11 [LP (Aus)]   37.4 19871442    NA 1 [party of 1st stack]
## 3 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        5         6.67       3.33     12 [ALP (Aus)]  45.1 19871442    NA 1 [party of 1st stack]
## 4 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        5         5.56       3.33     12 [ALP (Aus)]  45.1 19871442    NA 1 [party of 1st stack]
## 5 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        5         6.67       7.78     13 [NP (Aus)]    8.9 19871442    NA 1 [party of 1st stack]
## 6 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        5         5.56       4.44     13 [NP (Aus)]    8.9 19871442    NA 1 [party of 1st stack]
## 7 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        7         6.67      NA        14 [AD (Aus)]    6.6 19871442    NA 1 [party of 1st stack]
## 8 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        6         5.56      NA        14 [AD (Aus)]    6.6 19871442    NA 1 [party of 1st stack]
```

``` r
dl7[dl7$Rid==19871815,]
```

```
## # A tibble: 8 × 14
##   Ec               Ey   Rwd Vt           Vn                     Pl        Ll           LRR        LRP        PartyID           Ps Rid       Rage Pi                    
##   <dbl+lbl>     <dbl> <dbl> <dbl+lbl>    <dbl+lbl>              <dbl+lbl> <dbl+lbl>    <dbl+lbl>  <dbl+lbl>  <dbl+lbl>      <dbl> <chr>    <dbl> <dbl+lbl>             
## 1 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         7            8.89       6.67      11 [LP (Aus)]   37.4 19871815    NA 3 [party of 3rd stack]
## 2 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA        10 [like]    10 [right] 10 [right] 11 [LP (Aus)]   37.4 19871815    NA 1 [party of 1st stack]
## 3 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         7            8.89       7.78      12 [ALP (Aus)]  45.1 19871815    NA 3 [party of 3rd stack]
## 4 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         0 [dislike] 10 [right]  0 [left]  12 [ALP (Aus)]  45.1 19871815    NA 1 [party of 1st stack]
## 5 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         7            8.89       8.89      13 [NP (Aus)]    8.9 19871815    NA 3 [party of 3rd stack]
## 6 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         0 [dislike] 10 [right] 10 [right] 13 [NP (Aus)]    8.9 19871815    NA 1 [party of 1st stack]
## 7 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA         8            8.89      NA         14 [AD (Aus)]    6.6 19871815    NA 3 [party of 3rd stack]
## 8 1 [Australia]  1987     1 1 [did vote] 1 [party of 1st stack] NA         0 [dislike] 10 [right] NA         14 [AD (Aus)]    6.6 19871815    NA 1 [party of 1st stack]
```

``` r
dl7[dl7$Rid==19872176,]
```

```
## # A tibble: 8 × 14
##   Ec               Ey   Rwd Vt           Vn                     Pl        Ll        LRR       LRP       PartyID           Ps Rid       Rage Pi                    
##   <dbl+lbl>     <dbl> <dbl> <dbl+lbl>    <dbl+lbl>              <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl>      <dbl> <chr>    <dbl> <dbl+lbl>             
## 1 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        6         NA         3.33     11 [LP (Aus)]   37.4 19872176    NA 2 [party of 2nd stack]
## 2 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        4         NA         5.56     11 [LP (Aus)]   37.4 19872176    NA 2 [party of 2nd stack]
## 3 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        7         NA        NA        12 [ALP (Aus)]  45.1 19872176    NA 2 [party of 2nd stack]
## 4 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        6         NA         6.67     12 [ALP (Aus)]  45.1 19872176    NA 2 [party of 2nd stack]
## 5 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        4         NA        NA        13 [NP (Aus)]    8.9 19872176    NA 2 [party of 2nd stack]
## 6 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        3         NA        NA        13 [NP (Aus)]    8.9 19872176    NA 2 [party of 2nd stack]
## 7 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        5         NA        NA        14 [AD (Aus)]    6.6 19872176    NA 2 [party of 2nd stack]
## 8 1 [Australia]  1987     1 1 [did vote] 2 [party of 2nd stack] NA        5         NA        NA        14 [AD (Aus)]    6.6 19872176    NA 2 [party of 2nd stack]
```

``` r
dl7[dl7$Rid==19872263,]
```

```
## # A tibble: 8 × 14
##   Ec               Ey   Rwd Vt           Vn                     Pl        Ll        LRR       LRP       PartyID           Ps Rid       Rage Pi                    
##   <dbl+lbl>     <dbl> <dbl> <dbl+lbl>    <dbl+lbl>              <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl>      <dbl> <chr>    <dbl> <dbl+lbl>             
## 1 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        7         2.22       2.22     11 [LP (Aus)]   37.4 19872263    NA 3 [party of 3rd stack]
## 2 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        5         5.56       5.56     11 [LP (Aus)]   37.4 19872263    NA 3 [party of 3rd stack]
## 3 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        7         2.22       6.67     12 [ALP (Aus)]  45.1 19872263    NA 3 [party of 3rd stack]
## 4 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        3         5.56       5.56     12 [ALP (Aus)]  45.1 19872263    NA 3 [party of 3rd stack]
## 5 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        5         2.22       2.22     13 [NP (Aus)]    8.9 19872263    NA 3 [party of 3rd stack]
## 6 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        5         5.56       3.33     13 [NP (Aus)]    8.9 19872263    NA 3 [party of 3rd stack]
## 7 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        5         2.22      NA        14 [AD (Aus)]    6.6 19872263    NA 3 [party of 3rd stack]
## 8 1 [Australia]  1987     1 1 [did vote] 3 [party of 3rd stack] NA        5         5.56      NA        14 [AD (Aus)]    6.6 19872263    NA 3 [party of 3rd stack]
```

``` r
#all the duplicate Rid/PartyID in dl7 have Pl==NA therefore will be excluded later on
dl7=dl7 %>% distinct(Rid,PartyID,.keep_all = TRUE)#get rid of duplicates
dl7=dcast(setDT(dl7), Ec+Ey+Rwd+Vt+Vn+LRR+Rid+Pi ~ PartyID, value.var = c("Pl","Ll","LRP","Ps"))#create wide dataset
#then code country:
dl7$Ey=as.numeric(dl7$Ey)
dl7=dl7[!(dl7$Ey %in% c(1987,1990)),]#get rid of elections without likability
dl7$Ec=as.numeric(dl7$Ec)
dl7$Ec=7
dl7$Rage=as.numeric(NA)#Respondent Age is not coded in LP dataset
#Vt#Vote Turnout (0 did not vote; 1 voted)
dl7$Vt=as.numeric(dl7$Vt)
#"Va"#Vote Alphabetical (here numbers), by vote share:
#(single parties for vote alphabetical)
# # 11         LP (Aus) Liberal - Vn==1
# # 12        ALP (Aus) Labor - Vn==2
# # 13         NP (Aus) Nationals - Vn==3
# # 14         AD (Aus) Democrats - Vn==4
dl7$Va=NA
dl7$Va[dl7$Ey==1993&dl7$Vn==2]=1#1993:12,11,13,14
dl7$Va[dl7$Ey==1993&dl7$Vn==1]=2
dl7$Va[dl7$Ey==1993&dl7$Vn==3]=3
dl7$Va[dl7$Ey==1993&dl7$Vn==4]=4
dl7$Va[dl7$Ey==1996&dl7$Vn==2]=1#1996:12,11,13,14
dl7$Va[dl7$Ey==1996&dl7$Vn==1]=2
dl7$Va[dl7$Ey==1996&dl7$Vn==3]=3
dl7$Va[dl7$Ey==1996&dl7$Vn==4]=4
dl7$Va[dl7$Ey==1998&dl7$Vn==2]=1#1998:12,11,13,14
dl7$Va[dl7$Ey==1998&dl7$Vn==1]=2
dl7$Va[dl7$Ey==1998&dl7$Vn==3]=3
dl7$Va[dl7$Ey==1998&dl7$Vn==4]=4
dl7$Va[dl7$Ey==2001&dl7$Vn==2]=1#2001:12,11,13,14
dl7$Va[dl7$Ey==2001&dl7$Vn==1]=2
dl7$Va[dl7$Ey==2001&dl7$Vn==3]=3
dl7$Va[dl7$Ey==2001&dl7$Vn==4]=4
dl7$Rwd=as.numeric(dl7$Rwd)#there is no information on weights, all are 1
#Number of Parties:
dl7$NP=NA
dl7$NP[dl7$Ey==1993]=4
dl7$NP[dl7$Ey==1996]=4
dl7$NP[dl7$Ey==1998]=4
dl7$NP[dl7$Ey==2001]=4
#party likability:
dl7$Pl.1=NA
dl7$Pl.2=NA
dl7$Pl.3=NA
dl7$Pl.4=NA
dl7$Pl.5=NA
dl7$Pl.6=NA
# dl7$Pl.7=NA
dl7$Pl.1[dl7$Ey==1993]=dl7$Pl_12[dl7$Ey==1993]#1993:12,11,13,14
dl7$Pl.2[dl7$Ey==1993]=dl7$Pl_11[dl7$Ey==1993]
dl7$Pl.3[dl7$Ey==1993]=dl7$Pl_13[dl7$Ey==1993]
dl7$Pl.4[dl7$Ey==1993]=dl7$Pl_14[dl7$Ey==1993]
dl7$Pl.1[dl7$Ey==1996]=dl7$Pl_12[dl7$Ey==1996]#1996:12,11,13,14
dl7$Pl.2[dl7$Ey==1996]=dl7$Pl_11[dl7$Ey==1996]
dl7$Pl.3[dl7$Ey==1996]=dl7$Pl_13[dl7$Ey==1996]
dl7$Pl.4[dl7$Ey==1996]=dl7$Pl_14[dl7$Ey==1996]
dl7$Pl.1[dl7$Ey==1998]=dl7$Pl_12[dl7$Ey==1998]#1998:12,11,13,14
dl7$Pl.2[dl7$Ey==1998]=dl7$Pl_11[dl7$Ey==1998]
dl7$Pl.3[dl7$Ey==1998]=dl7$Pl_13[dl7$Ey==1998]
dl7$Pl.4[dl7$Ey==1998]=dl7$Pl_14[dl7$Ey==1998]
dl7$Pl.1[dl7$Ey==2001]=dl7$Pl_12[dl7$Ey==2001]#2001:12,11,13,14
dl7$Pl.2[dl7$Ey==2001]=dl7$Pl_11[dl7$Ey==2001]
dl7$Pl.3[dl7$Ey==2001]=dl7$Pl_13[dl7$Ey==2001]
dl7$Pl.4[dl7$Ey==2001]=dl7$Pl_14[dl7$Ey==2001]
#already 0-10 scale
#leader likability:
dl7$Ll.1=NA
dl7$Ll.2=NA
dl7$Ll.3=NA
dl7$Ll.4=NA
dl7$Ll.5=NA
dl7$Ll.6=NA
# dl7$Ll.7=NA
dl7$Ll.1[dl7$Ey==1993]=dl7$Ll_12[dl7$Ey==1993]#1993:12,11,13,14
dl7$Ll.2[dl7$Ey==1993]=dl7$Ll_11[dl7$Ey==1993]
dl7$Ll.3[dl7$Ey==1993]=dl7$Ll_13[dl7$Ey==1993]
dl7$Ll.4[dl7$Ey==1993]=dl7$Ll_14[dl7$Ey==1993]
dl7$Ll.1[dl7$Ey==1996]=dl7$Ll_12[dl7$Ey==1996]#1996:12,11,13,14
dl7$Ll.2[dl7$Ey==1996]=dl7$Ll_11[dl7$Ey==1996]
dl7$Ll.3[dl7$Ey==1996]=dl7$Ll_13[dl7$Ey==1996]
dl7$Ll.4[dl7$Ey==1996]=dl7$Ll_14[dl7$Ey==1996]
dl7$Ll.1[dl7$Ey==1998]=dl7$Ll_12[dl7$Ey==1998]#1998:12,11,13,14
dl7$Ll.2[dl7$Ey==1998]=dl7$Ll_11[dl7$Ey==1998]
dl7$Ll.3[dl7$Ey==1998]=dl7$Ll_13[dl7$Ey==1998]
dl7$Ll.4[dl7$Ey==1998]=dl7$Ll_14[dl7$Ey==1998]
dl7$Ll.1[dl7$Ey==2001]=dl7$Ll_12[dl7$Ey==2001]#2001:12,11,13,14
dl7$Ll.2[dl7$Ey==2001]=dl7$Ll_11[dl7$Ey==2001]
dl7$Ll.3[dl7$Ey==2001]=dl7$Ll_13[dl7$Ey==2001]
dl7$Ll.4[dl7$Ey==2001]=dl7$Ll_14[dl7$Ey==2001]
#already 0-10 scale
#LRR=Left Right Respondent (voter LR self):
dl7$LRR=as.numeric(dl7$LRR)
#already 0-10 scale
#LRP.i=Left Right Parties:
dl7$LRP.1=NA
dl7$LRP.2=NA
dl7$LRP.3=NA
dl7$LRP.4=NA
dl7$LRP.5=NA
dl7$LRP.6=NA
# dl7$LRP.7=NA
dl7$LRP.1[dl7$Ey==1993]=dl7$LRP_12[dl7$Ey==1993]#1993:12,11,13,14
dl7$LRP.2[dl7$Ey==1993]=dl7$LRP_11[dl7$Ey==1993]
dl7$LRP.3[dl7$Ey==1993]=dl7$LRP_13[dl7$Ey==1993]
dl7$LRP.4[dl7$Ey==1993]=dl7$LRP_14[dl7$Ey==1993]
dl7$LRP.1[dl7$Ey==1996]=dl7$LRP_12[dl7$Ey==1996]#1996:12,11,13,14
dl7$LRP.2[dl7$Ey==1996]=dl7$LRP_11[dl7$Ey==1996]
dl7$LRP.3[dl7$Ey==1996]=dl7$LRP_13[dl7$Ey==1996]
dl7$LRP.4[dl7$Ey==1996]=dl7$LRP_14[dl7$Ey==1996]
dl7$LRP.1[dl7$Ey==1998]=dl7$LRP_12[dl7$Ey==1998]#1998:12,11,13,14
dl7$LRP.2[dl7$Ey==1998]=dl7$LRP_11[dl7$Ey==1998]
dl7$LRP.3[dl7$Ey==1998]=dl7$LRP_13[dl7$Ey==1998]
dl7$LRP.4[dl7$Ey==1998]=dl7$LRP_14[dl7$Ey==1998]
dl7$LRP.1[dl7$Ey==2001]=dl7$LRP_12[dl7$Ey==2001]#2001:12,11,13,14
dl7$LRP.2[dl7$Ey==2001]=dl7$LRP_11[dl7$Ey==2001]
dl7$LRP.3[dl7$Ey==2001]=dl7$LRP_13[dl7$Ey==2001]
dl7$LRP.4[dl7$Ey==2001]=dl7$LRP_14[dl7$Ey==2001]
#already 0-10 scale
#Elections with LRR and LRP:
dl7$LR=NA
dl7$LR[dl7$Ey==1993]=0
dl7$LR[dl7$Ey==1996]=1
dl7$LR[dl7$Ey==1998]=1
dl7$LR[dl7$Ey==2001]=1
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
dl7$EeconS=NA#(no data)
#Elections with EeconS:
dl7$Eecon=0#(no data)
#Seats to vote ratios:
dl7$P1P2rat=NA
dl7$P1P2rat[dl7$Ey==1993]=1.21#recoding AUS_1996 percent vote: Liberal and National in coalition becoming
dl7$P1P2rat[dl7$Ey==1996]=1.57#the biggest (party A); and the Labor Party the second (party B); but ONLY for the shares
dl7$P1P2rat[dl7$Ey==1998]=1.24#(by seats)
dl7$P1P2rat[dl7$Ey==2001]=1.11
#Gallagher Disproportionality measure:
dl7$GDM=NA
dl7$GDM[dl7$Ey==1993]=8.12
dl7$GDM[dl7$Ey==1996]=8.12
dl7$GDM[dl7$Ey==1998]=10.87
dl7$GDM[dl7$Ey==2001]=9.37
#Party family:
dl7$PartyFamilyCode11=60
dl7$PartyFamilyCode12=30
dl7$PartyFamilyCode13=80
dl7$PartyFamilyCode14=30
#"Va"#Vote Alphabetical (here numbers), by vote share:
#(single parties for vote alphabetical)
# # 11         LP (Aus) Liberal - Vn==1
# # 12        ALP (Aus) Labor - Vn==2
# # 13         NP (Aus) Nationals - Vn==3
# # 14         AD (Aus) Democrats - Vn==4
dl7$Pf.1=NA
dl7$Pf.2=NA
dl7$Pf.3=NA
dl7$Pf.4=NA
dl7$Pf.5=NA
dl7$Pf.6=NA
# dl7$Pf.7=NA
dl7$Pf.1[dl7$Ey==1993]=dl7$PartyFamilyCode12[dl7$Ey==1993]#1993:12,11,13,14
dl7$Pf.2[dl7$Ey==1993]=dl7$PartyFamilyCode11[dl7$Ey==1993]
dl7$Pf.3[dl7$Ey==1993]=dl7$PartyFamilyCode13[dl7$Ey==1993]
dl7$Pf.4[dl7$Ey==1993]=dl7$PartyFamilyCode14[dl7$Ey==1993]
dl7$Pf.1[dl7$Ey==1996]=dl7$PartyFamilyCode12[dl7$Ey==1996]#1996:12,11,13,14
dl7$Pf.2[dl7$Ey==1996]=dl7$PartyFamilyCode11[dl7$Ey==1996]
dl7$Pf.3[dl7$Ey==1996]=dl7$PartyFamilyCode13[dl7$Ey==1996]
dl7$Pf.4[dl7$Ey==1996]=dl7$PartyFamilyCode14[dl7$Ey==1996]
dl7$Pf.1[dl7$Ey==1998]=dl7$PartyFamilyCode12[dl7$Ey==1998]#1998:12,11,13,14
dl7$Pf.2[dl7$Ey==1998]=dl7$PartyFamilyCode11[dl7$Ey==1998]
dl7$Pf.3[dl7$Ey==1998]=dl7$PartyFamilyCode13[dl7$Ey==1998]
dl7$Pf.4[dl7$Ey==1998]=dl7$PartyFamilyCode14[dl7$Ey==1998]
dl7$Pf.1[dl7$Ey==2001]=dl7$PartyFamilyCode12[dl7$Ey==2001]#2001:12,11,13,14
dl7$Pf.2[dl7$Ey==2001]=dl7$PartyFamilyCode11[dl7$Ey==2001]
dl7$Pf.3[dl7$Ey==2001]=dl7$PartyFamilyCode13[dl7$Ey==2001]
dl7$Pf.4[dl7$Ey==2001]=dl7$PartyFamilyCode14[dl7$Ey==2001]
#coding coalition status:
dl7$CoalCode=1
#CMPid.i:
dl7$CMPid.1=NA#create CMPid:
dl7$CMPid.2=NA
dl7$CMPid.3=NA
dl7$CMPid.4=NA
dl7$CMPid.5=NA
dl7$CMPid.6=NA
dl7$CMPid.1[dl7$Ey==1993]=63320#assign CMPid by party size order for parties with likability:
dl7$CMPid.2[dl7$Ey==1993]=63620
dl7$CMPid.3[dl7$Ey==1993]=63810
dl7$CMPid.4[dl7$Ey==1993]=NA
dl7$CMPid.1[dl7$Ey==1998]=63320
dl7$CMPid.2[dl7$Ey==1998]=63620
dl7$CMPid.3[dl7$Ey==1998]=63810
dl7$CMPid.4[dl7$Ey==1998]=63321
dl7$CMPid.1[dl7$Ey==2001]=63320
dl7$CMPid.2[dl7$Ey==2001]=63620
dl7$CMPid.3[dl7$Ey==2001]=63810
dl7$CMPid.4[dl7$Ey==2001]=NA
dl7$CMPid.1=as.numeric(dl7$CMPid.1)#recode as numeric:
dl7$CMPid.2=as.numeric(dl7$CMPid.2)
dl7$CMPid.3=as.numeric(dl7$CMPid.3)
dl7$CMPid.4=as.numeric(dl7$CMPid.4)
dl7$CMPid.5=as.numeric(dl7$CMPid.5)
dl7$CMPid.6=as.numeric(dl7$CMPid.6)
#PrePost:
dl7$PrePost=as.numeric(NA)
dl7$PrePost[dl7$Ey==1993]=1
#"Pi"#Party identification:
dl7$Pitemp=dl7$Pi#set Pi to Pitemp for ordering Pi by seat share
dl7$Pi=NA
dl7$Pi[dl7$Ey==1993&dl7$Pitemp==2]=1#1993:12,11,13,14
dl7$Pi[dl7$Ey==1993&dl7$Pitemp==1]=2
dl7$Pi[dl7$Ey==1993&dl7$Pitemp==3]=3
dl7$Pi[dl7$Ey==1993&dl7$Pitemp==4]=4
# dl7$Pi[dl7$Ey==1961&dl7$Pitemp<97&!(dl7$Pitemp %in% c(2,1,3))]=7#INCLUDING PARTY #7: NOT DONE FROM NOW ON!!!
dl7$Pi[dl7$Ey==1996&dl7$Pitemp==2]=1#1996:12,11,13,14
dl7$Pi[dl7$Ey==1996&dl7$Pitemp==1]=2
dl7$Pi[dl7$Ey==1996&dl7$Pitemp==3]=3
dl7$Pi[dl7$Ey==1996&dl7$Pitemp==4]=4
dl7$Pi[dl7$Ey==1998&dl7$Pitemp==2]=1#1998:12,11,13,14
dl7$Pi[dl7$Ey==1998&dl7$Pitemp==1]=2
dl7$Pi[dl7$Ey==1998&dl7$Pitemp==3]=3
dl7$Pi[dl7$Ey==1998&dl7$Pitemp==4]=4
dl7$Pi[dl7$Ey==2001&dl7$Pitemp==2]=1#2001:12,11,13,14
dl7$Pi[dl7$Ey==2001&dl7$Pitemp==1]=2
dl7$Pi[dl7$Ey==2001&dl7$Pitemp==3]=3
dl7$Pi[dl7$Ey==2001&dl7$Pitemp==4]=4
dl7$Pi=as.numeric(dl7$Pi)
#subset:
colnames(dl7)
```

```
##  [1] "Ec"                "Ey"                "Rwd"               "Vt"                "Vn"                "LRR"               "Rid"               "Pi"                "Pl_11"             "Pl_12"             "Pl_13"             "Pl_14"             "Ll_11"             "Ll_12"             "Ll_13"             "Ll_14"             "LRP_11"            "LRP_12"            "LRP_13"            "LRP_14"            "Ps_11"             "Ps_12"             "Ps_13"             "Ps_14"             "Rage"              "Va"                "NP"                "Pl.1"              "Pl.2"              "Pl.3"              "Pl.4"              "Pl.5"              "Pl.6"              "Ll.1"              "Ll.2"              "Ll.3"              "Ll.4"              "Ll.5"              "Ll.6"              "LRP.1"             "LRP.2"             "LRP.3"             "LRP.4"             "LRP.5"             "LRP.6"             "LR"                "EeconS"            "Eecon"             "P1P2rat"          
## [50] "GDM"               "PartyFamilyCode11" "PartyFamilyCode12" "PartyFamilyCode13" "PartyFamilyCode14" "Pf.1"              "Pf.2"              "Pf.3"              "Pf.4"              "Pf.5"              "Pf.6"              "CoalCode"          "CMPid.1"           "CMPid.2"           "CMPid.3"           "CMPid.4"           "CMPid.5"           "CMPid.6"           "PrePost"           "Pitemp"
```

``` r
dl7=dl7[,c(1,2,3,27,4,26,28:39,46,6,40:45,48,47,49,50,55:68,25,8)]
dl7=as.data.frame(dl7)
colnames(dl7)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
# dl7[colnames(dl7)]=sapply(dl7[colnames(dl7)],as.numeric)


#CANADA LP dl8:----
dl8=dl[dl$Ec==2,]#create country dataset
#first reshape to wide dataset:
dl8$Vn[dl8$Vn==10]=NA#set Vn==NA for NAs
dl8$Rid=paste0(dl8$Ey,dl8$Rid)#create unique Rid
dl8=dl8[dl8$Ey!=1980,]#there is not Rid in dl8 1980
colnames(dl8)
```

```
##  [1] "Ec"      "Ey"      "Rwd"     "Vt"      "Vn"      "Pl"      "Ll"      "LRR"     "LRP"     "PartyID" "Ps"      "Rid"     "Rage"    "Pi"
```

``` r
dl8[c(which(duplicated(dl8[,c(10,12)]))),]#rows with duplicated Rid/PartyID observations
```

```
## # A tibble: 0 × 14
## # ℹ 14 variables: Ec <dbl+lbl>, Ey <dbl>, Rwd <dbl>, Vt <dbl+lbl>, Vn <dbl+lbl>, Pl <dbl+lbl>, Ll <dbl+lbl>, LRR <dbl+lbl>, LRP <dbl+lbl>, PartyID <dbl+lbl>, Ps <dbl>, Rid <chr>, Rage <dbl>, Pi <dbl+lbl>
```

``` r
unique(dl8$Rid[duplicated(dl8[,c(10,12)])])#Rid for rows with duplicated Rid/PartyID observations
```

```
## character(0)
```

``` r
#there is no duplicate Rid/PartyID in dl8
dl8=dl8 %>% distinct(Rid,PartyID,.keep_all = TRUE)#get rid of duplicates (redundant)
dl8=dcast(setDT(dl8), Ec+Ey+Rwd+Vt+Vn+LRR+Rid+Pi ~ PartyID, value.var = c("Pl","Ll","LRP","Ps"))#create wide dataset
#then code country:
dl8$Ey=as.numeric(dl8$Ey)
dl8$Ec=as.numeric(dl8$Ec)
dl8$Ec=8
dl8$Rage=as.numeric(NA)#Respondent Age is not coded in LP dataset
#Vt#Vote Turnout (0 did not vote; 1 voted)
dl8$Vt=as.numeric(dl8$Vt)
#"Va"#Vote Alphabetical (here numbers), by vote share:
#(single parties for vote alphabetical)
# # 21        LPC (Can) Liberal - Vn==1
# # 22         PC (Can) Progressive Conservative - Vn==2
# # 23        NDP (Can) New Democratic - Vn==3
# # 24         CA (Can) Reform - Vn==4
# # 25         BQ (Can) Bloc Québécois - Vn==5
dl8$Va=NA
dl8$Va[dl8$Ey==1968&dl8$Vn==1]=1#1968:21,22,23
dl8$Va[dl8$Ey==1968&dl8$Vn==2]=2
dl8$Va[dl8$Ey==1968&dl8$Vn==3]=3
dl8$Va[dl8$Ey==1974&dl8$Vn==1]=1#1974:21,22,23
dl8$Va[dl8$Ey==1974&dl8$Vn==2]=2
dl8$Va[dl8$Ey==1974&dl8$Vn==3]=3
dl8$Va[dl8$Ey==1979&dl8$Vn==1]=1#1979:21,22,23(by vote, not seats, as CSES)
dl8$Va[dl8$Ey==1979&dl8$Vn==2]=2
dl8$Va[dl8$Ey==1979&dl8$Vn==3]=3
dl8$Va[dl8$Ey==1988&dl8$Vn==2]=1#1988:22,21,23
dl8$Va[dl8$Ey==1988&dl8$Vn==1]=2
dl8$Va[dl8$Ey==1988&dl8$Vn==3]=3
dl8$Va[dl8$Ey==1993&dl8$Vn==1]=1#1993:21,24,22,25,23(by vote, not seats, as CSES)
dl8$Va[dl8$Ey==1993&dl8$Vn==4]=2
dl8$Va[dl8$Ey==1993&dl8$Vn==2]=3
dl8$Va[dl8$Ey==1993&dl8$Vn==5]=4
dl8$Va[dl8$Ey==1993&dl8$Vn==3]=5
dl8$Va[dl8$Ey==1997&dl8$Vn==1]=1#1997:21,24,22,23,25(by vote, not seats, as CSES)
dl8$Va[dl8$Ey==1997&dl8$Vn==4]=2
dl8$Va[dl8$Ey==1997&dl8$Vn==2]=3
dl8$Va[dl8$Ey==1997&dl8$Vn==3]=4
dl8$Va[dl8$Ey==1997&dl8$Vn==5]=5
dl8$Rwd=as.numeric(dl8$Rwd)
#Number of Parties:
dl8$NP=NA
dl8$NP[dl8$Ey==1968]=3
dl8$NP[dl8$Ey==1974]=3
dl8$NP[dl8$Ey==1979]=3
dl8$NP[dl8$Ey==1988]=3
dl8$NP[dl8$Ey==1993]=5
dl8$NP[dl8$Ey==1997]=5
#party likability:
dl8$Pl.1=NA
dl8$Pl.2=NA
dl8$Pl.3=NA
dl8$Pl.4=NA
dl8$Pl.5=NA
dl8$Pl.6=NA
# dl8$Pl.7=NA
dl8$Pl.1[dl8$Ey==1968]=dl8$Pl_21[dl8$Ey==1968]#1968:21,22,23
dl8$Pl.2[dl8$Ey==1968]=dl8$Pl_22[dl8$Ey==1968]
dl8$Pl.3[dl8$Ey==1968]=dl8$Pl_23[dl8$Ey==1968]
dl8$Pl.1[dl8$Ey==1974]=dl8$Pl_21[dl8$Ey==1974]#1974:21,22,23
dl8$Pl.2[dl8$Ey==1974]=dl8$Pl_22[dl8$Ey==1974]
dl8$Pl.3[dl8$Ey==1974]=dl8$Pl_23[dl8$Ey==1974]
dl8$Pl.1[dl8$Ey==1979]=dl8$Pl_21[dl8$Ey==1979]#1979:21,22,23(by vote, not seats, as CSES)
dl8$Pl.2[dl8$Ey==1979]=dl8$Pl_22[dl8$Ey==1979]
dl8$Pl.3[dl8$Ey==1979]=dl8$Pl_23[dl8$Ey==1979]
dl8$Pl.1[dl8$Ey==1988]=dl8$Pl_22[dl8$Ey==1988]#1988:22,21,23
dl8$Pl.2[dl8$Ey==1988]=dl8$Pl_21[dl8$Ey==1988]
dl8$Pl.3[dl8$Ey==1988]=dl8$Pl_23[dl8$Ey==1988]
dl8$Pl.1[dl8$Ey==1993]=dl8$Pl_21[dl8$Ey==1993]#1993:21,24,22,25,23(by vote, not seats, as CSES)
dl8$Pl.2[dl8$Ey==1993]=dl8$Pl_24[dl8$Ey==1993]
dl8$Pl.3[dl8$Ey==1993]=dl8$Pl_22[dl8$Ey==1993]
dl8$Pl.4[dl8$Ey==1993]=dl8$Pl_25[dl8$Ey==1993]
dl8$Pl.5[dl8$Ey==1993]=dl8$Pl_23[dl8$Ey==1993]
dl8$Pl.1[dl8$Ey==1997]=dl8$Pl_21[dl8$Ey==1997]#1997:21,24,22,23,25(by vote, not seats, as CSES)
dl8$Pl.2[dl8$Ey==1997]=dl8$Pl_24[dl8$Ey==1997]
dl8$Pl.3[dl8$Ey==1997]=dl8$Pl_22[dl8$Ey==1997]
dl8$Pl.4[dl8$Ey==1997]=dl8$Pl_23[dl8$Ey==1997]
dl8$Pl.5[dl8$Ey==1997]=dl8$Pl_25[dl8$Ey==1997]
#already 0-10 scale
#leader likability:
dl8$Ll.1=NA
dl8$Ll.2=NA
dl8$Ll.3=NA
dl8$Ll.4=NA
dl8$Ll.5=NA
dl8$Ll.6=NA
# dl8$Ll.7=NA
dl8$Ll.1[dl8$Ey==1968]=dl8$Ll_21[dl8$Ey==1968]#1968:21,22,23
dl8$Ll.2[dl8$Ey==1968]=dl8$Ll_22[dl8$Ey==1968]
dl8$Ll.3[dl8$Ey==1968]=dl8$Ll_23[dl8$Ey==1968]
dl8$Ll.1[dl8$Ey==1974]=dl8$Ll_21[dl8$Ey==1974]#1974:21,22,23
dl8$Ll.2[dl8$Ey==1974]=dl8$Ll_22[dl8$Ey==1974]
dl8$Ll.3[dl8$Ey==1974]=dl8$Ll_23[dl8$Ey==1974]
dl8$Ll.1[dl8$Ey==1979]=dl8$Ll_21[dl8$Ey==1979]#1979:21,22,23(by vote, not seats, as CSES)
dl8$Ll.2[dl8$Ey==1979]=dl8$Ll_22[dl8$Ey==1979]
dl8$Ll.3[dl8$Ey==1979]=dl8$Ll_23[dl8$Ey==1979]
dl8$Ll.1[dl8$Ey==1988]=dl8$Ll_22[dl8$Ey==1988]#1988:22,21,23
dl8$Ll.2[dl8$Ey==1988]=dl8$Ll_21[dl8$Ey==1988]
dl8$Ll.3[dl8$Ey==1988]=dl8$Ll_23[dl8$Ey==1988]
dl8$Ll.1[dl8$Ey==1993]=dl8$Ll_21[dl8$Ey==1993]#1993:21,24,22,25,23(by vote, not seats, as CSES)
dl8$Ll.2[dl8$Ey==1993]=dl8$Ll_24[dl8$Ey==1993]
dl8$Ll.3[dl8$Ey==1993]=dl8$Ll_22[dl8$Ey==1993]
dl8$Ll.4[dl8$Ey==1993]=dl8$Ll_25[dl8$Ey==1993]
dl8$Ll.5[dl8$Ey==1993]=dl8$Ll_23[dl8$Ey==1993]
dl8$Ll.1[dl8$Ey==1997]=dl8$Ll_21[dl8$Ey==1997]#1997:21,24,22,23,25(by vote, not seats, as CSES)
dl8$Ll.2[dl8$Ey==1997]=dl8$Ll_24[dl8$Ey==1997]
dl8$Ll.3[dl8$Ey==1997]=dl8$Ll_22[dl8$Ey==1997]
dl8$Ll.4[dl8$Ey==1997]=dl8$Ll_23[dl8$Ey==1997]
dl8$Ll.5[dl8$Ey==1997]=dl8$Ll_25[dl8$Ey==1997]
#LRR=Left Right Respondent (voter LR self):
dl8$LRR=as.numeric(dl8$LRR)
#(no data)
#LRP.i=Left Right Parties:
dl8$LRP.1=NA#(no data)
dl8$LRP.2=NA#(no data)
dl8$LRP.3=NA#(no data)
dl8$LRP.4=NA#(no data)
dl8$LRP.5=NA#(no data)
dl8$LRP.6=NA#(no data)
# dl8$LRP.7=NA#(no data)
#Elections with LRR and LRP:
dl8$LR=NA#(no data)
#EeconS=Election economy state Subjective:(Retrospective socio-tropic economic evaluations)
dl8$EeconS=NA#(no data)
#Elections with EeconS:
dl8$Eecon=0#(no data)
#Seats to vote ratios:
dl8$P1P2rat=NA
dl8$P1P2rat[dl8$Ey==1968]=1.48
dl8$P1P2rat[dl8$Ey==1974]=1.22
dl8$P1P2rat[dl8$Ey==1979]=1.34#(by seats)
dl8$P1P2rat[dl8$Ey==1988]=1.51
dl8$P1P2rat[dl8$Ey==1993]=1.07#(by seats)
dl8$P1P2rat[dl8$Ey==1997]=1.30#(by seats)
#Gallagher Disproportionality measure:
dl8$GDM=NA
dl8$GDM[dl8$Ey==1968]=11.58
dl8$GDM[dl8$Ey==1974]=9.86
dl8$GDM[dl8$Ey==1979]=10.41
dl8$GDM[dl8$Ey==1988]=11.33
dl8$GDM[dl8$Ey==1993]=17.67
dl8$GDM[dl8$Ey==1997]=13.26
#Party family:
dl8$PartyFamilyCode21=40
dl8$PartyFamilyCode22=60
dl8$PartyFamilyCode23=30
dl8$PartyFamilyCode24=60
dl8$PartyFamilyCode25=90
#(single parties for vote alphabetical)
# # 21        LPC (Can) Liberal - Vn==1
# # 22         PC (Can) Progressive Conservative - Vn==2
# # 23        NDP (Can) New Democratic - Vn==3
# # 24         CA (Can) Reform - Vn==4
# # 25         BQ (Can) Bloc Québécois - Vn==5
dl8$Pf.1=NA
dl8$Pf.2=NA
dl8$Pf.3=NA
dl8$Pf.4=NA
dl8$Pf.5=NA
dl8$Pf.6=NA
# dl8$Pf.7=NA
dl8$Pf.1[dl8$Ey==1968]=dl8$PartyFamilyCode21[dl8$Ey==1968]#1968:21,22,23
dl8$Pf.2[dl8$Ey==1968]=dl8$PartyFamilyCode22[dl8$Ey==1968]
dl8$Pf.3[dl8$Ey==1968]=dl8$PartyFamilyCode23[dl8$Ey==1968]
dl8$Pf.1[dl8$Ey==1974]=dl8$PartyFamilyCode21[dl8$Ey==1974]#1974:21,22,23
dl8$Pf.2[dl8$Ey==1974]=dl8$PartyFamilyCode22[dl8$Ey==1974]
dl8$Pf.3[dl8$Ey==1974]=dl8$PartyFamilyCode23[dl8$Ey==1974]
dl8$Pf.1[dl8$Ey==1979]=dl8$PartyFamilyCode21[dl8$Ey==1979]#1979:21,22,23(by vote, not seats, as CSES)
dl8$Pf.2[dl8$Ey==1979]=dl8$PartyFamilyCode22[dl8$Ey==1979]
dl8$Pf.3[dl8$Ey==1979]=dl8$PartyFamilyCode23[dl8$Ey==1979]
dl8$Pf.1[dl8$Ey==1988]=dl8$PartyFamilyCode22[dl8$Ey==1988]#1988:22,21,23
dl8$Pf.2[dl8$Ey==1988]=dl8$PartyFamilyCode21[dl8$Ey==1988]
dl8$Pf.3[dl8$Ey==1988]=dl8$PartyFamilyCode23[dl8$Ey==1988]
dl8$Pf.1[dl8$Ey==1993]=dl8$PartyFamilyCode21[dl8$Ey==1993]#1993:21,24,22,25,23(by vote, not seats, as CSES)
dl8$Pf.2[dl8$Ey==1993]=dl8$PartyFamilyCode24[dl8$Ey==1993]
dl8$Pf.3[dl8$Ey==1993]=dl8$PartyFamilyCode22[dl8$Ey==1993]
dl8$Pf.4[dl8$Ey==1993]=dl8$PartyFamilyCode25[dl8$Ey==1993]
dl8$Pf.5[dl8$Ey==1993]=dl8$PartyFamilyCode23[dl8$Ey==1993]
dl8$Pf.1[dl8$Ey==1997]=dl8$PartyFamilyCode21[dl8$Ey==1997]#1997:21,24,22,23,25(by vote, not seats, as CSES)
dl8$Pf.2[dl8$Ey==1997]=dl8$PartyFamilyCode24[dl8$Ey==1997]
dl8$Pf.3[dl8$Ey==1997]=dl8$PartyFamilyCode22[dl8$Ey==1997]
dl8$Pf.4[dl8$Ey==1997]=dl8$PartyFamilyCode23[dl8$Ey==1997]
dl8$Pf.5[dl8$Ey==1997]=dl8$PartyFamilyCode25[dl8$Ey==1997]
#coding coalition status:
dl8$CoalCode=0
#CMPid.i:
dl8$CMPid.1=NA#create CMPid:
dl8$CMPid.2=NA
dl8$CMPid.3=NA
dl8$CMPid.4=NA
dl8$CMPid.5=NA
dl8$CMPid.6=NA
dl8$CMPid.1[dl8$Ey==1968]=62420#assign CMPid by party size order for parties with likability:
dl8$CMPid.2[dl8$Ey==1968]=62620
dl8$CMPid.3[dl8$Ey==1968]=62320
dl8$CMPid.1[dl8$Ey==1974]=62420
dl8$CMPid.2[dl8$Ey==1974]=62620
dl8$CMPid.3[dl8$Ey==1974]=62320
dl8$CMPid.1[dl8$Ey==1979]=62420
dl8$CMPid.2[dl8$Ey==1979]=62620
dl8$CMPid.3[dl8$Ey==1979]=62320
dl8$CMPid.1[dl8$Ey==1988]=62620
dl8$CMPid.2[dl8$Ey==1988]=62420
dl8$CMPid.3[dl8$Ey==1988]=62320
dl8$CMPid.1[dl8$Ey==1993]=62420
dl8$CMPid.2[dl8$Ey==1993]=62621
dl8$CMPid.3[dl8$Ey==1993]=62620
dl8$CMPid.4[dl8$Ey==1993]=62901
dl8$CMPid.5[dl8$Ey==1993]=62320
dl8$CMPid.1=as.numeric(dl8$CMPid.1)#recode as numeric:
dl8$CMPid.2=as.numeric(dl8$CMPid.2)
dl8$CMPid.3=as.numeric(dl8$CMPid.3)
dl8$CMPid.4=as.numeric(dl8$CMPid.4)
dl8$CMPid.5=as.numeric(dl8$CMPid.5)
dl8$CMPid.6=as.numeric(dl8$CMPid.6)
#PrePost:
dl8$PrePost=as.numeric(NA)
dl8$PrePost[dl8$Ey==1968]=1
dl8$PrePost[dl8$Ey==1974]=1
dl8$PrePost[dl8$Ey==1979]=1
dl8$PrePost[dl8$Ey==1988]=3
dl8$PrePost[dl8$Ey==1993]=3
#"Pi"#Party identification:
dl8$Pitemp=dl8$Pi#set Pi to Pitemp for ordering Pi by seat share
dl8$Pi=NA
dl8$Pi[dl8$Ey==1968&dl8$Pitemp==1]=1#1968:21,22,23
dl8$Pi[dl8$Ey==1968&dl8$Pitemp==2]=2
dl8$Pi[dl8$Ey==1968&dl8$Pitemp==3]=3
dl8$Pi[dl8$Ey==1974&dl8$Pitemp==1]=1#1974:21,22,23
dl8$Pi[dl8$Ey==1974&dl8$Pitemp==2]=2
dl8$Pi[dl8$Ey==1974&dl8$Pitemp==3]=3
dl8$Pi[dl8$Ey==1979&dl8$Pitemp==1]=1#1979:21,22,23(by vote, not seats, as CSES)
dl8$Pi[dl8$Ey==1979&dl8$Pitemp==2]=2
dl8$Pi[dl8$Ey==1979&dl8$Pitemp==3]=3
dl8$Pi[dl8$Ey==1988&dl8$Pitemp==2]=1#1988:22,21,23
dl8$Pi[dl8$Ey==1988&dl8$Pitemp==1]=2
dl8$Pi[dl8$Ey==1988&dl8$Pitemp==3]=3
dl8$Pi[dl8$Ey==1993&dl8$Pitemp==1]=1#1993:21,24,22,25,23(by vote, not seats, as CSES)
dl8$Pi[dl8$Ey==1993&dl8$Pitemp==4]=2
dl8$Pi[dl8$Ey==1993&dl8$Pitemp==2]=3
dl8$Pi[dl8$Ey==1993&dl8$Pitemp==5]=4
dl8$Pi[dl8$Ey==1993&dl8$Pitemp==3]=5
dl8$Pi[dl8$Ey==1997&dl8$Pitemp==1]=1#1997:21,24,22,23,25(by vote, not seats, as CSES)
dl8$Pi[dl8$Ey==1997&dl8$Pitemp==4]=2
dl8$Pi[dl8$Ey==1997&dl8$Pitemp==2]=3
dl8$Pi[dl8$Ey==1997&dl8$Pitemp==3]=4
dl8$Pi[dl8$Ey==1997&dl8$Pitemp==5]=5
dl8$Pi=as.numeric(dl8$Pi)
#subset:
colnames(dl8)
```

```
##  [1] "Ec"                "Ey"                "Rwd"               "Vt"                "Vn"                "LRR"               "Rid"               "Pi"                "Pl_21"             "Pl_22"             "Pl_23"             "Pl_24"             "Pl_25"             "Ll_21"             "Ll_22"             "Ll_23"             "Ll_24"             "Ll_25"             "LRP_21"            "LRP_22"            "LRP_23"            "LRP_24"            "LRP_25"            "Ps_21"             "Ps_22"             "Ps_23"             "Ps_24"             "Ps_25"             "Rage"              "Va"                "NP"                "Pl.1"              "Pl.2"              "Pl.3"              "Pl.4"              "Pl.5"              "Pl.6"              "Ll.1"              "Ll.2"              "Ll.3"              "Ll.4"              "Ll.5"              "Ll.6"              "LRP.1"             "LRP.2"             "LRP.3"             "LRP.4"             "LRP.5"             "LRP.6"            
## [50] "LR"                "EeconS"            "Eecon"             "P1P2rat"           "GDM"               "PartyFamilyCode21" "PartyFamilyCode22" "PartyFamilyCode23" "PartyFamilyCode24" "PartyFamilyCode25" "Pf.1"              "Pf.2"              "Pf.3"              "Pf.4"              "Pf.5"              "Pf.6"              "CoalCode"          "CMPid.1"           "CMPid.2"           "CMPid.3"           "CMPid.4"           "CMPid.5"           "CMPid.6"           "PrePost"           "Pitemp"
```

``` r
dl8=dl8[,c(1,2,3,31,4,30,32:43,50,6,44:49,52,51,53,54,60:73,29,8)]
dl8=as.data.frame(dl8)
colnames(dl8)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
# dl8[colnames(dl8)]=sapply(dl8[colnames(dl8)],as.numeric)


#DL SPAIN (dl9):----
#all elections are already coded in tev, therefore not coded.


#MERGE EV AND LP:----

#merge European Voter dataset, and the Leadership Project Dataset in de:
de=rbind(de1,de2,de3,de4,de5,de6,dl7,dl8)
colnames(de)
```

```
##  [1] "Ec"       "Ey"       "Rwd"      "NP"       "Vt"       "Va"       "Pl.1"     "Pl.2"     "Pl.3"     "Pl.4"     "Pl.5"     "Pl.6"     "Ll.1"     "Ll.2"     "Ll.3"     "Ll.4"     "Ll.5"     "Ll.6"     "LR"       "LRR"      "LRP.1"    "LRP.2"    "LRP.3"    "LRP.4"    "LRP.5"    "LRP.6"    "Eecon"    "EeconS"   "P1P2rat"  "GDM"      "Pf.1"     "Pf.2"     "Pf.3"     "Pf.4"     "Pf.5"     "Pf.6"     "CoalCode" "CMPid.1"  "CMPid.2"  "CMPid.3"  "CMPid.4"  "CMPid.5"  "CMPid.6"  "PrePost"  "Rage"     "Pi"
```

``` r
rm(de1,de2,de3,de4,de5,de6,dl7,dl8,dl)

#creating variable missing in one of the datasets compared to the other:
de$Ec[de$Ec==1]="GBR"
de$Ec[de$Ec==2]="DNK"
de$Ec[de$Ec==3]="DEU"
de$Ec[de$Ec==4]="NLD"
de$Ec[de$Ec==5]="NOR"
de$Ec[de$Ec==6]="SWE"
de$Ec[de$Ec==7]="AUS"
de$Ec[de$Ec==8]="CAN"
de$Es=paste0(de$Ec,"_",de$Ey)#election study


#creating party family voted party:----
x=as.data.frame(de)
X=x[, names(x) %in% paste0("Pf.", 1:6)]
X=as.matrix(X)
de$VPf=NA
for (i in 1:nrow(de)) {
  de$VPf[i]=X[i,de$Va[i]]
}
rm(x,X)


#Pv.i (pervote):----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="pervote"]="Pv"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

dCMP$Ey[dCMP$Ec=="GBR"&dCMP$date==197410]=1975#set temporary Ey for double elections

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,16)]

#code pervote alternative i (Pv.i):
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T, all.y=F)
colnames(de)[colnames(de)=="Pv"]="Pv.1"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Pv"]="Pv.2"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Pv"]="Pv.3"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Pv"]="Pv.4"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Pv"]="Pv.5"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Pv"]="Pv.6"


#Ps.i (perseats):----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="absseat"]="Ps"
colnames(dCMP)[colnames(dCMP)=="totseats"]="Pst"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

dCMP$Ey[dCMP$Ec=="GBR"&dCMP$date==197410]=1975#set temporary Ey for double elections

#code total seats:
dCMP_temp=dCMP[,c(175,176,7,20)]
de=merge(de, dCMP_temp, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T, all.y=F)
rm(dCMP_temp)

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,19)]

#code seats alternative i (Ps.i):
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Ps"]="Ps.1"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Ps"]="Ps.2"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Ps"]="Ps.3"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Ps"]="Ps.4"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Ps"]="Ps.5"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="Ps"]="Ps.6"

#get seat share %:
de$Ps.1=de$Ps.1/de$Pst*100
de$Ps.2=de$Ps.2/de$Pst*100
de$Ps.3=de$Ps.3/de$Pst*100
de$Ps.4=de$Ps.4/de$Pst*100
de$Ps.5=de$Ps.5/de$Pst*100
de$Ps.6=de$Ps.6/de$Pst*100


#Seats to vote ratios:----
de$P1SVrat=de$Ps.1/de$Pv.1#for most voted party
de$P2SVrat=de$Ps.2/de$Pv.2#for second most voted party
de$P1P2rat=de$P1SVrat/de$P2SVrat#ratio of rations first/second party
summary(de$P1P2rat)
```

```
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    0.75    1.00    1.06    1.23    1.51    1.93   54884
```

``` r
#Gallagher Disproportionality measure:----
#(coded only for the elections that will remain in the final dataset)
de$GDM=NA
de$GDM[de$Es=="AUS_1993"]=8.12
de$GDM[de$Es=="CAN_1968"]=11.58
de$GDM[de$Es=="CAN_1974"]=9.86
de$GDM[de$Es=="CAN_1979"]=10.41
de$GDM[de$Es=="CAN_1988"]=11.33
de$GDM[de$Es=="CAN_1993"]=17.67
de$GDM[de$Es=="DNK_1971"]=3.45
de$GDM[de$Es=="DNK_1973"]=1.20
de$GDM[de$Es=="DNK_1994"]=1.57
de$GDM[de$Es=="GBR_1974"]=15.47#1974f
de$GDM[de$Es=="GBR_1975"]=14.96#1974o
de$GDM[de$Es=="GBR_1979"]=11.58
de$GDM[de$Es=="NLD_1986"]=1.67


#CMPrile:----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="rile"]="CMPrile"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

dCMP$Ey[dCMP$Ec=="GBR"&dCMP$date==197410]=1975#set temporary Ey for double elections

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,168)]

#code pervote alternative i (CMPrile.i):
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPrile"]="CMPrile.1"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPrile"]="CMPrile.2"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPrile"]="CMPrile.3"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPrile"]="CMPrile.4"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPrile"]="CMPrile.5"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPrile"]="CMPrile.6"


#CMPper415:----

#read CMP dataset:
dCMP=read.xlsx("MPDataset_MPDS2020b.xlsx")

#filter CMP dataset and set variable names:
colnames(dCMP)[colnames(dCMP)=="party"]="CMPid_temp"
colnames(dCMP)[colnames(dCMP)=="per415"]="CMPper415"

dCMP$Ec=NA
dCMP$Ec=as.character(dCMP$Ec)
dCMP$Ec[dCMP$country==63]="AUS"
dCMP$Ec[dCMP$country==42]="AUT"
dCMP$Ec[dCMP$country==62]="CAN"
dCMP$Ec[dCMP$country==41]="DEU"
dCMP$Ec[dCMP$country==13]="DNK"
dCMP$Ec[dCMP$country==33]="ESP"
dCMP$Ec[dCMP$country==14]="FIN"
dCMP$Ec[dCMP$country==51]="GBR"
dCMP$Ec[dCMP$country==34]="GRC"
dCMP$Ec[dCMP$country==53]="IRL"
dCMP$Ec[dCMP$country==15]="ISL"
dCMP$Ec[dCMP$country==72]="ISR"
dCMP$Ec[dCMP$country==32]="ITA"
dCMP$Ec[dCMP$country==22]="NLD"
dCMP$Ec[dCMP$country==12]="NOR"
dCMP$Ec[dCMP$country==64]="NZL"
dCMP$Ec[dCMP$country==35]="PRT"
dCMP$Ec[dCMP$country==11]="SWE"
dCMP$Ec[dCMP$country==83]="EST"#
dCMP$Ec[dCMP$country==86]="HUN"
dCMP$Ec[dCMP$country==88]="LTU"
dCMP$Ec[dCMP$country==97]="SVN"

dCMP$Ey=as.numeric(substr(dCMP$date,1,4))

dCMP$Ey[dCMP$Ec=="GBR"&dCMP$date==197410]=1975#set temporary Ey for double elections

#keep only variables of interest:
dCMP=dCMP[,c(175,176,7,59)]

#code pervote alternative i (CMPper415.i):
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.1"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPper415"]="CMPper415.1"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.2"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPper415"]="CMPper415.2"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.3"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPper415"]="CMPper415.3"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.4"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPper415"]="CMPper415.4"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.5"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPper415"]="CMPper415.5"
de=merge(de, dCMP, by.x=c("Ec","Ey","CMPid.6"), by.y=c("Ec","Ey","CMPid_temp"), all.x=T)
colnames(de)[colnames(de)=="CMPper415"]="CMPper415.6"


#Ed election dataset:----
de$Ed="EV-LP"


#Rid Respondent ID:----
de$Rid=NA#there is not unique ID


#SET DOUBLE ELECTIONS BACK TO ORIGINAL VALUES:----

#settign GBR 1974 elections back to correct year and election study:
de$Es[de$Ec=="GBR"&de$Ey==1974]="GBR_1974f"#February election
de$Es[de$Ec=="GBR"&de$Ey==1975]="GBR_1974o"#October election
de$Ey[de$Ec=="GBR"&de$Ey==1975]=1974


#FILTER AND MERGE EV-LP AND CSES:----

#keep in EV-LP only elections not already present in CSES:
sort(unique(dc$Es[dc$Es %in% c(sort(unique(de$Es)))]))
```

```
## [1] "AUS_1996" "CAN_1997" "DEU_1998" "DNK_1998" "GBR_1997" "NLD_1998" "NOR_1997" "SWE_1998"
```

``` r
#"AUS_1996" "CAN_1997" "DEU_1998" "DNK_1998" "GBR_1997" "NLD_1998" "NOR_1997" "SWE_1998"
de=de[!(de$Es %in% c(sort(unique(dc$Es)))),]

#filter European Voter and CSES data:
names(dc)
```

```
##  [1] "Ec"          "Ey"          "Es"          "Ed"          "Rid"         "Rwd"         "Rage"        "NP"          "CoalCode"    "Vt"          "Va"          "Vn"          "Pl.1"        "Pl.2"        "Pl.3"        "Pl.4"        "Pl.5"        "Pl.6"        "Ll.1"        "Ll.2"        "Ll.3"        "Ll.4"        "Ll.5"        "Ll.6"        "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "LRP.4"       "LRP.5"       "LRP.6"       "EeconS"      "P1P2rat"     "GDM"         "VPf"         "PrePost"     "Pv.1"        "Pv.2"        "Pv.3"        "Pv.4"        "Pv.5"        "Pv.6"        "Ps.1"        "Ps.2"        "Ps.3"        "Ps.4"        "Ps.5"        "Ps.6"        "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPrile.4"   "CMPrile.5"   "CMPrile.6"   "CSESid.1"    "CSESid.2"    "CSESid.3"    "CSESid.4"    "CSESid.5"    "CSESid.6"    "CMPid.1"     "CMPid.2"     "CMPid.3"     "CMPid.4"     "CMPid.5"     "CMPid.6"     "CMPper415.1" "CMPper415.2" "CMPper415.3" "CMPper415.4" "CMPper415.5"
## [72] "CMPper415.6" "Pi"
```

``` r
names(de)
```

```
##  [1] "Ec"          "Ey"          "CMPid.6"     "CMPid.5"     "CMPid.4"     "CMPid.3"     "CMPid.2"     "CMPid.1"     "Rwd"         "NP"          "Vt"          "Va"          "Pl.1"        "Pl.2"        "Pl.3"        "Pl.4"        "Pl.5"        "Pl.6"        "Ll.1"        "Ll.2"        "Ll.3"        "Ll.4"        "Ll.5"        "Ll.6"        "LR"          "LRR"         "LRP.1"       "LRP.2"       "LRP.3"       "LRP.4"       "LRP.5"       "LRP.6"       "Eecon"       "EeconS"      "P1P2rat"     "GDM"         "Pf.1"        "Pf.2"        "Pf.3"        "Pf.4"        "Pf.5"        "Pf.6"        "CoalCode"    "PrePost"     "Rage"        "Pi"          "Es"          "VPf"         "Pv.1"        "Pv.2"        "Pv.3"        "Pv.4"        "Pv.5"        "Pv.6"        "Pst"         "Ps.1"        "Ps.2"        "Ps.3"        "Ps.4"        "Ps.5"        "Ps.6"        "P1SVrat"     "P2SVrat"     "CMPrile.1"   "CMPrile.2"   "CMPrile.3"   "CMPrile.4"   "CMPrile.5"   "CMPrile.6"   "CMPper415.1" "CMPper415.2"
## [72] "CMPper415.3" "CMPper415.4" "CMPper415.5" "CMPper415.6" "Ed"          "Rid"
```

``` r
dc=dc[,-c(12,55:60)]
de=de[,c(1:2,47,76,77,9,45,10,43,11,12,13:24,26,27:32,34:36,48,44,49:54,56:61,64:69,8:3,70:75,46)]


#merge European Voter and CSES data in de:
de=rbind(de,dc)
rm(dc)
de=as.data.frame(de)


#SAVE DATA:----
dew=de#remane to match TEV data creation code
rm(de)
save(dew, file = "d29_CSES-EV-LP.RData")
```

